Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function getConfigTreeBuilder()
$rootNode
->children()
->integerNode('minimum_input_length')->min(0)->defaultValue(1)->end()
->integerNode('minimum_results_for_search')->defaultValue(6)->end()
->booleanNode('scroll')->defaultFalse()->end()
->integerNode('page_limit')->defaultValue(10)->end()
->booleanNode('allow_clear')->defaultFalse()->end()
Expand Down
3 changes: 2 additions & 1 deletion Form/Type/Select2EntityType.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public function configureOptions(OptionsResolver $resolver)
'multiple' => false,
'compound' => false,
'minimum_input_length' => $this->config['minimum_input_length'],
'minimum_results_for_search' => $this->config['minimum_results_for_search'],
'page_limit' => $this->config['page_limit'],
'scroll' => $this->config['scroll'],
'allow_clear' => $this->config['allow_clear'],
Expand All @@ -163,7 +164,7 @@ public function configureOptions(OptionsResolver $resolver)
'text_property' => null,
'placeholder' => false,
'language' => $this->config['language'],
'theme' => $this->config['theme'],
'theme' => $this->config['theme'],
'required' => false,
'cache' => $this->config['cache'],
'cache_timeout' => $this->config['cache_timeout'],
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ Defaults will be used for some if not set.
If text_property is omitted then the entity is cast to a string. This requires it to have a __toString() method.
* `multiple` True for multiple select (many to many). False for single (many to one) select.
* `minimum_input_length` is the number of keys you need to hit before the search will happen. Defaults to 2.
* `minimum_results_for_search` option determines the minimum number of results required in the initial population of the dropdown to display the search box. Defaults to 6.
* `page_limit` This is passed as a query parameter to the remote call. It is intended to be used to limit size of the list returned. Defaults to 10.
* `scroll` True will enable infinite scrolling. Defaults to false.
* `allow_clear` True will cause Select2 to display a small x for clearing the value. Defaults to false.
Expand Down Expand Up @@ -152,6 +153,7 @@ The defaults can be changed in your config/packages/tetranzselect2entity.yaml fi
```yaml
tetranz_select2_entity:
minimum_input_length: 2
minimum_results_for_search: 6
page_limit: 8
allow_clear: true
delay: 500
Expand Down Expand Up @@ -341,6 +343,19 @@ Because the handling of requests is usually very similar you can use a service w
}
```

### Limiting display of the search box to large result sets

This option is useful for cases where local data is used with a small result set, and the search box would simply be a waste of screen real estate. Set this value to -1 to permanently hide the search box:

```php
$builder
->add('tags', Select2EntityType::class, [
'remote_route' => 'tetranz_user_types',
'class' => '\Tetranz\TestBundle\Entity\UserType',
'text_property' => 'name',
'minimum_results_for_search' => -1
]);
```

### Templating

Expand Down
1 change: 1 addition & 0 deletions Resources/views/Form/fields.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
'data-language' :language,
'data-theme' :theme,
'data-minimum-input-length': minimum_input_length,
'data-minimum-results-for-search': minimum_results_for_search,
'data-placeholder': placeholder|trans({}, translation_domain),
'data-page-limit': page_limit,
'data-scroll': scroll ? 'true' : 'false',
Expand Down