Skip to content

Commit 5eb4f5e

Browse files
committed
Update README.md
1 parent 8a20579 commit 5eb4f5e

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

Form/Type/Select2EntityType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function finishView(FormView $view, FormInterface $form, array $options)
124124
//tags options
125125
$varNames = array_keys($this->config['allow_add']);
126126
foreach ($varNames as $varName) {
127-
$view->vars['allow_add'][$varName] = $options['allow_add'][$varName] ?? $this->config['allow_add'][$varName];;
127+
$view->vars['allow_add'][$varName] = $options['allow_add'][$varName] ?? $this->config['allow_add'][$varName];
128128
}
129129

130130
if ($options['multiple']) {

README.md

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
[Note from project maintainer: June 17th 2019](https://github.com/tetranz/select2entity-bundle/issues/144)
2-
31
select2entity-bundle
42
====================
53

64
## Introduction
75

86
This is a Symfony bundle which enables the popular [Select2](https://select2.github.io) component to be used as a drop-in replacement for a standard entity field on a Symfony form.
97

10-
It works with Symfony 2, 3 and 4.
8+
It works with Symfony 4 and 5. For Symfony 2 and 3, please use version or 2.x of the bundle.
9+
For Select2 4.0 and above. For older versions, use version 1.x of the bundle (not compatible with Symfony 5).
1110

1211
The main feature that this bundle provides compared with the standard Symfony entity field (rendered with a html select) is that the list is retrieved via a remote ajax call. This means that the list can be of almost unlimited size. The only limitation is the performance of the database query or whatever that retrieves the data in the remote web service.
1312

@@ -53,32 +52,32 @@ Alternatively, minified versions of select2.js and select2.css can be loaded fro
5352
Note that this only works with Select2 version 4. If you are using Select2 version 3.X please use `"tetranz/select2entity-bundle": "1.*"` in `composer.json`
5453

5554
* Run `php composer.phar update tetranz/select2entity-bundle` in your project root.
56-
* Update your project `app/AppKernel.php` file and add this bundle to the $bundles array:
55+
* Update your project `config/bundles.php` file and add this bundle to the $bundles array:
5756

5857
```php
59-
$bundles = array(
58+
$bundles = [
6059
// ...
61-
new Tetranz\Select2EntityBundle\TetranzSelect2EntityBundle(),
62-
);
60+
Tetranz\Select2EntityBundle\TetranzSelect2EntityBundle::class => ['all' => true]
61+
];
6362
```
6463

65-
* Update your project `app/config.yml` file to provide global twig form templates:
64+
* Update your project `config/packages/twig.yaml` file to provide global twig form templates:
6665

6766
```yaml
6867
twig:
6968
form_themes:
70-
- 'TetranzSelect2EntityBundle:Form:fields.html.twig'
71-
72-
```
73-
On Symfony 4, use `@TetranzSelect2Entity/Form/fields.html.twig` instead of `TetranzSelect2EntityBundle:Form:fields.html.twig`
69+
- '@TetranzSelect2Entity/Form/fields.html.twig'
70+
7471
* Load the Javascript on the page. The simplest way is to add the following to your layout file. Don't forget to run console assets:install. Alternatively, do something more sophisticated with Assetic.
72+
```
73+
7574
```
7675
<script src="{{ asset('bundles/tetranzselect2entity/js/select2entity.js') }}"></script>
7776
```
7877

7978
## How to use
8079

81-
The following is for Symfony 3. The latest version works on both Symfony 2 and Symfony 3 but see https://github.com/tetranz/select2entity-bundle/tree/v2.1 for Symfony 2 configuration and use.
80+
The following is for Symfony 4. See https://github.com/tetranz/select2entity-bundle/tree/v2.1 for Symfony 2/3 configuration and use.
8281

8382
Select2Entity is simple to use. In the buildForm method of a form type class, specify `Select2EntityType::class` as the type where you would otherwise use `entity:class`.
8483

@@ -89,6 +88,7 @@ $builder
8988
->add('country', Select2EntityType::class, [
9089
'multiple' => true,
9190
'remote_route' => 'tetranz_test_default_countryquery',
91+
'remote_params' => [] // static route parameters for request->query
9292
'class' => '\Tetranz\TestBundle\Entity\Country',
9393
'primary_key' => 'id',
9494
'text_property' => 'name',
@@ -100,6 +100,11 @@ $builder
100100
'cache_timeout' => 60000, // if 'cache' is true
101101
'language' => 'en',
102102
'placeholder' => 'Select a country',
103+
'query_parameters' => [
104+
'start' => new \DateTime()
105+
'end' => (new \DateTime())->modify('+5d')
106+
// any other parameters you want your ajax route request->query to get, that you might want to modify dynamically
107+
],
103108
// 'object_manager' => $objectManager, // inject a custom object / entity manager
104109
])
105110
```
@@ -138,18 +143,21 @@ The url of the remote query can be given by either of two ways: `remote_route` i
138143
`remote_params` can be optionally specified to provide parameters. Alternatively, `remote_path` can be used to specify
139144
the url directly.
140145

141-
The defaults can be changed in your app/config.yml file with the following format.
146+
You may use `query_parameters` for when those remote_params have to be changeable dynamically. You may change them using $('#elem).data('query-parameters', { /* new params */ });
147+
148+
The defaults can be changed in your config/packages/tetranzselect2entity.yaml file with the following format.
142149

143150
```yaml
144151
tetranz_select2_entity:
145152
minimum_input_length: 2
146153
page_limit: 8
147154
allow_clear: true
148155
delay: 500
149-
language: fr
156+
language: 'fr'
150157
cache: false
151158
cache_timeout: 0
152159
scroll: true
160+
object_manager: 'manager_alias'
153161
```
154162
155163
## AJAX Response

0 commit comments

Comments
 (0)