From 125d54e162954a2114f4d8a9c95ea59d7c080041 Mon Sep 17 00:00:00 2001 From: Tim Mallezie Date: Tue, 21 Apr 2015 08:09:13 +0200 Subject: [PATCH] dont add select2 class and placeholder to all select elements --- CRM/Core/Form.php | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index 3a05f9884e..6bd0e20700 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -1207,20 +1207,10 @@ class CRM_Core_Form extends HTML_QuickForm_Page { else { $options = isset($fieldSpec['options']) ? $fieldSpec['options'] : NULL; } - - // The placeholder is only used for select-elements. - if (!array_key_exists('placeholder', $props)) { - $props['placeholder'] = $required ? ts('- select -') : $props['context'] == 'search' ? ts('- any -') : ts('- none -'); - } - + //@TODO AdvMulti-Select is deprecated, drop support. if ($props['context'] == 'search' || ($widget !== 'AdvMulti-Select' && strpos($widget, 'Select') !== FALSE)) { $widget = 'Select'; } - $props['class'] = (isset($props['class']) ? $props['class'] . ' ' : '') . "crm-select2"; - if ($props['context'] == 'search' || strpos($widget, 'Multi') !== FALSE) { - $props['class'] .= ' huge'; - $props['multiple'] = 'multiple'; - } // Set default options-url value. if ((!isset($props['options-url']))) { $props['options-url'] = TRUE; @@ -1236,6 +1226,26 @@ class CRM_Core_Form extends HTML_QuickForm_Page { } } } + //Use select2 library for following widgets. + $isSelect2 = (in_array($widget, array( + 'Select', + 'Multi-Select', + 'Select State/Province', + 'Multi-Select State/Province', + 'Select Country', + 'Multi-Select Country', + ))); + if ($isSelect2) { + $props['class'] = (isset($props['class']) ? $props['class'] . ' ' : '') . "crm-select2"; + if ($props['context'] == 'search' || strpos($widget, 'Multi') !== FALSE) { + $props['class'] .= ' huge'; + $props['multiple'] = 'multiple'; + } + // The placeholder is only used for select-elements. + if (!array_key_exists('placeholder', $props)) { + $props['placeholder'] = $required ? ts('- select -') : $props['context'] == 'search' ? ts('- any -') : ts('- none -'); + } + } $props += CRM_Utils_Array::value('html', $fieldSpec, array()); CRM_Utils_Array::remove($props, 'entity', 'name', 'context', 'label', 'action', 'type'); // TODO: refactor switch statement, to seperate methods. @@ -1256,11 +1266,11 @@ class CRM_Core_Form extends HTML_QuickForm_Page { //TODO: Add javascript template for dates. case 'Radio': $separator = isset($props['separator']) ? $props['separator'] : NULL; - unset($props['seperator']); + unset($props['separator']); if (!isset($props['allowClear'])) { - $attributes['allowClear'] = !$required; + $props['allowClear'] = !$required; } - $this->addRadio($name, $label, $options, $attributes, $separator, $required); + $this->addRadio($name, $label, $options, $props, $separator, $required); break; case 'Select': -- 2.25.1