From b248d52b402e6201aad0beb801983d606552db1d Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 25 Dec 2015 21:36:21 -0500 Subject: [PATCH] Improve CRM_Core_Form::addField for ChainSelect types --- CRM/Core/Form.php | 16 ++++++++++------ xml/schema/Core/Address.xml | 6 +++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index ff90dc0b95..183f4b40c7 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -1437,15 +1437,19 @@ class CRM_Core_Form extends HTML_QuickForm_Page { } return $this->addRadio($name, $label, $options, $props, $separator, $required); + case 'ChainSelect': + $props += array( + 'required' => $required, + 'label' => $label, + 'multiple' => $props['context'] == 'search', + ); + return $this->addChainSelect($name, $props); + case 'Select': - $props['class'] = CRM_Utils_Array::value('class', $props, 'big'); - $props['class'] .= ' crm-select2'; + $props['class'] = CRM_Utils_Array::value('class', $props, 'big') . ' crm-select2'; if (!array_key_exists('placeholder', $props)) { $props['placeholder'] = $required ? ts('- select -') : $props['context'] == 'search' ? ts('- any -') : ts('- none -'); } - if (!empty($props['data-api-field']) && (in_array($props['data-api-field'], array('state_province_id', 'county_id')))) { - return $this->addChainSelect($name, $props); - } // TODO: Add and/or option for fields that store multiple values return $this->add('select', $name, $label, $options, $required, $props); @@ -2151,7 +2155,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page { 'required' => FALSE, 'placeholder' => empty($settings['required']) ? ts('- none -') : ts('- select -'), ); - CRM_Utils_Array::remove($props, 'label', 'required', 'control_field'); + CRM_Utils_Array::remove($props, 'label', 'required', 'control_field', 'context'); $props['class'] = (empty($props['class']) ? '' : "{$props['class']} ") . 'crm-select2'; $props['data-select-prompt'] = $props['placeholder']; $props['data-name'] = $elementName; diff --git a/xml/schema/Core/Address.xml b/xml/schema/Core/Address.xml index 6585bc4e91..028b4bed3e 100644 --- a/xml/schema/Core/Address.xml +++ b/xml/schema/Core/Address.xml @@ -257,7 +257,7 @@ name - Select + ChainSelect 1.1 @@ -273,7 +273,7 @@ state_province_id - State + State/Province int unsigned Which State_Province does this address belong to. @@ -282,7 +282,7 @@ name - Select + ChainSelect 1.1 -- 2.25.1