Skip to content

Commit 60b146d

Browse files
authored
Merge pull request tetranz#157 from alexndlm/master
Add "theme" option
2 parents 7e6a504 + a20dba0 commit 60b146d

File tree

4 files changed

+9
-0
lines changed

4 files changed

+9
-0
lines changed

DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function getConfigTreeBuilder()
3636
->end()
3737
->integerNode('delay')->defaultValue(250)->min(0)->end()
3838
->scalarNode('language')->defaultValue('en')->end()
39+
->scalarNode('theme')->defaultValue('default')->end()
3940
->booleanNode('cache')->defaultTrue()->end()
4041
->integerNode('cache_timeout')->defaultValue(60000)->min(0)->end()
4142
->scalarNode('width')->defaultNull()->end()

Form/Type/Select2EntityType.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ public function configureOptions(OptionsResolver $resolver)
163163
'text_property' => null,
164164
'placeholder' => false,
165165
'language' => $this->config['language'],
166+
'theme' => $this->config['theme'],
166167
'required' => false,
167168
'cache' => $this->config['cache'],
168169
'cache_timeout' => $this->config['cache_timeout'],

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ If text_property is omitted then the entity is cast to a string. This requires i
132132
* `delay` The delay in milliseconds after a keystroke before trigging another AJAX request. Defaults to 250 ms.
133133
* `placeholder` Placeholder text.
134134
* `language` i18n language code. Defaults to en.
135+
* `theme` Defaults to 'default'.
135136
* `cache` Enable AJAX cache. Results will be cached for each 'term' queried.
136137
* `cache_timeout` How long to cache a query in milliseconds. Setting to `0` will cause the cache to never timeout _(60000 = 60 seconds)_
137138
* `transformer` The fully qualified class name of a custom transformer if you need that flexibility as described below.
@@ -155,6 +156,7 @@ tetranz_select2_entity:
155156
allow_clear: true
156157
delay: 500
157158
language: 'fr'
159+
theme: 'default'
158160
cache: false
159161
cache_timeout: 0
160162
scroll: true
@@ -408,6 +410,10 @@ You also will need to override the following block in your template:
408410
```
409411
This block adds all additional data needed to the JavaScript function `select2entityAjax`, like data attribute. In this case we are passing `data-img`.</details>
410412

413+
### Themes
414+
Select2 supports custom themes using the `theme` option so you can style Select2 to match the rest of your application.
415+
For Bootstrap4 theme look at https://github.com/ttskch/select2-bootstrap4-theme
416+
411417
## Embed Collection Forms
412418
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`:
413419
```javascript

Resources/views/Form/fields.html.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
'data-ajax--delay': delay,
77
'data-ajax--data-type': "json",
88
'data-language' :language,
9+
'data-theme' :theme,
910
'data-minimum-input-length': minimum_input_length,
1011
'data-placeholder': placeholder|trans({}, translation_domain),
1112
'data-page-limit': page_limit,

0 commit comments

Comments
 (0)