From 9b740f2ad2dfa821150f12cc3baf48dc164584d6 Mon Sep 17 00:00:00 2001 From: Roni Kumar Saha Date: Sat, 16 May 2020 17:30:16 +0600 Subject: [PATCH] Allow to configure maximum_selection_length option --- DependencyInjection/Configuration.php | 1 + Form/Type/Select2EntityType.php | 1 + Resources/views/Form/fields.html.twig | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 5bd9542..2bae987 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -22,6 +22,7 @@ public function getConfigTreeBuilder() $rootNode ->children() + ->integerNode('maximum_selection_length')->defaultNull()->end() ->integerNode('minimum_input_length')->min(0)->defaultValue(1)->end() ->booleanNode('scroll')->defaultFalse()->end() ->integerNode('page_limit')->defaultValue(10)->end() diff --git a/Form/Type/Select2EntityType.php b/Form/Type/Select2EntityType.php index 74f5f2d..bd2709a 100644 --- a/Form/Type/Select2EntityType.php +++ b/Form/Type/Select2EntityType.php @@ -149,6 +149,7 @@ public function configureOptions(OptionsResolver $resolver) 'remote_params' => [], 'multiple' => false, 'compound' => false, + 'maximum_selection_length' => $this->config['maximum_selection_length'], 'minimum_input_length' => $this->config['minimum_input_length'], 'page_limit' => $this->config['page_limit'], 'scroll' => $this->config['scroll'], diff --git a/Resources/views/Form/fields.html.twig b/Resources/views/Form/fields.html.twig index c508e7e..c2f9687 100644 --- a/Resources/views/Form/fields.html.twig +++ b/Resources/views/Form/fields.html.twig @@ -29,6 +29,10 @@ {% set attr = attr|merge({'multiple': 'multiple'}) %} {% endif %} + {% if maximum_selection_length %} + {% set attr = attr|merge({'data-maximum-selection-length': maximum_selection_length}) %} + {% endif %} + {% if query_parameters %} {% set attr = attr|merge({ 'data-query-parameters': query_parameters|json_encode