From 404e6ca25188b7f4902f970f2157c2fb32d98641 Mon Sep 17 00:00:00 2001 From: alexndlm Date: Tue, 15 Oct 2019 10:34:41 +0300 Subject: [PATCH 1/4] Update Configuration.php --- DependencyInjection/Configuration.php | 1 + 1 file changed, 1 insertion(+) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 0873825..5bd9542 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -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() From b825b4a53571638c0a4608830c5f2dcabbbdf136 Mon Sep 17 00:00:00 2001 From: alexndlm Date: Tue, 15 Oct 2019 10:35:47 +0300 Subject: [PATCH 2/4] Update Select2EntityType.php --- Form/Type/Select2EntityType.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Form/Type/Select2EntityType.php b/Form/Type/Select2EntityType.php index e2ca2f5..74f5f2d 100644 --- a/Form/Type/Select2EntityType.php +++ b/Form/Type/Select2EntityType.php @@ -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'], From b55a5f48f43a07ffe5d1b70f85b7390c7416d19a Mon Sep 17 00:00:00 2001 From: alexndlm Date: Tue, 15 Oct 2019 10:36:35 +0300 Subject: [PATCH 3/4] Update fields.html.twig --- Resources/views/Form/fields.html.twig | 1 + 1 file changed, 1 insertion(+) diff --git a/Resources/views/Form/fields.html.twig b/Resources/views/Form/fields.html.twig index c6b524a..c508e7e 100644 --- a/Resources/views/Form/fields.html.twig +++ b/Resources/views/Form/fields.html.twig @@ -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, From a20dba0f3330ea2400b76d1ea29a77dcc965e6c4 Mon Sep 17 00:00:00 2001 From: alexndlm Date: Tue, 15 Oct 2019 10:54:04 +0300 Subject: [PATCH 4/4] Update README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 0647f7f..be126e6 100644 --- a/README.md +++ b/README.md @@ -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. @@ -155,6 +156,7 @@ tetranz_select2_entity: allow_clear: true delay: 500 language: 'fr' + theme: 'default' cache: false cache_timeout: 0 scroll: true @@ -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`. +### 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