Skip to content

Commit

Permalink
Merge pull request #157 from alexndlm/master
Browse files Browse the repository at this point in the history
Add "theme" option
  • Loading branch information
tetranz authored Oct 19, 2019
2 parents 7e6a504 + a20dba0 commit 60b146d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function getConfigTreeBuilder()
->end()
->integerNode('delay')->defaultValue(250)->min(0)->end()
->scalarNode('language')->defaultValue('en')->end()
->scalarNode('theme')->defaultValue('default')->end()
->booleanNode('cache')->defaultTrue()->end()
->integerNode('cache_timeout')->defaultValue(60000)->min(0)->end()
->scalarNode('width')->defaultNull()->end()
Expand Down
1 change: 1 addition & 0 deletions Form/Type/Select2EntityType.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ public function configureOptions(OptionsResolver $resolver)
'text_property' => null,
'placeholder' => false,
'language' => $this->config['language'],
'theme' => $this->config['theme'],
'required' => false,
'cache' => $this->config['cache'],
'cache_timeout' => $this->config['cache_timeout'],
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ If text_property is omitted then the entity is cast to a string. This requires i
* `delay` The delay in milliseconds after a keystroke before trigging another AJAX request. Defaults to 250 ms.
* `placeholder` Placeholder text.
* `language` i18n language code. Defaults to en.
* `theme` Defaults to 'default'.
* `cache` Enable AJAX cache. Results will be cached for each 'term' queried.
* `cache_timeout` How long to cache a query in milliseconds. Setting to `0` will cause the cache to never timeout _(60000 = 60 seconds)_
* `transformer` The fully qualified class name of a custom transformer if you need that flexibility as described below.
Expand All @@ -155,6 +156,7 @@ tetranz_select2_entity:
allow_clear: true
delay: 500
language: 'fr'
theme: 'default'
cache: false
cache_timeout: 0
scroll: true
Expand Down Expand Up @@ -408,6 +410,10 @@ You also will need to override the following block in your template:
```
This block adds all additional data needed to the JavaScript function `select2entityAjax`, like data attribute. In this case we are passing `data-img`.</details>

### Themes
Select2 supports custom themes using the `theme` option so you can style Select2 to match the rest of your application.
For Bootstrap4 theme look at https://github.com/ttskch/select2-bootstrap4-theme

## Embed Collection Forms
If you use [Embedded Collection Forms](http://symfony.com/doc/current/cookbook/form/form_collections.html) and [data-prototype](http://symfony.com/doc/current/cookbook/form/form_collections.html#allowing-new-tags-with-the-prototype) to add new elements in your form, you will need the following JavaScript that will listen for adding an element `.select2entity`:
```javascript
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 @@ -6,6 +6,7 @@
'data-ajax--delay': delay,
'data-ajax--data-type': "json",
'data-language' :language,
'data-theme' :theme,
'data-minimum-input-length': minimum_input_length,
'data-placeholder': placeholder|trans({}, translation_domain),
'data-page-limit': page_limit,
Expand Down

0 comments on commit 60b146d

Please sign in to comment.