Improve CRM_Core_Form::addField for ChainSelect types
authorColeman Watts <coleman@civicrm.org>
Sat, 26 Dec 2015 02:36:21 +0000 (21:36 -0500)
committerColeman Watts <coleman@civicrm.org>
Sat, 26 Dec 2015 03:09:43 +0000 (22:09 -0500)
CRM/Core/Form.php
xml/schema/Core/Address.xml

index ff90dc0b95963cdf0f3c709a6b8d923ecbbca7a0..183f4b40c793d496fb2278b434de54260889f320 100644 (file)
@@ -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;
index 6585bc4e91d2fb84ca1f9cdb4f5e865659f43ccc..028b4bed3e3b67115a7c3dac62a093e9528966e8 100644 (file)
       <labelColumn>name</labelColumn>
     </pseudoconstant>
     <html>
-      <type>Select</type>
+      <type>ChainSelect</type>
     </html>
     <add>1.1</add>
   </field>
   </foreignKey>
   <field>
     <name>state_province_id</name>
-    <title>State</title>
+    <title>State/Province</title>
     <type>int unsigned</type>
     <comment>Which State_Province does this address belong to.</comment>
     <pseudoconstant>
       <labelColumn>name</labelColumn>
     </pseudoconstant>
     <html>
-      <type>Select</type>
+      <type>ChainSelect</type>
     </html>
     <add>1.1</add>
   </field>