$selectAttributes = array('class' => 'crm-select2', 'placeholder' => TRUE);
- // CRM-15172 - keep track of all the fields we've processed
- // This is hackish but we can't always rely on $form->_fields depending on how this is called
- static $fieldsProcessed = array();
- $fieldsProcessed[] = $name;
-
if ($fieldName == 'image_URL' && $mode == CRM_Profile_Form::MODE_EDIT) {
$deleteExtra = ts('Are you sure you want to delete contact image.');
$deleteURL = array(
);
if (substr($fieldName, 0, 14) === 'state_province') {
- $controlField = str_replace('state_province', 'country', $name);
- if (isset($form->_fields[$controlField]) || in_array($controlField, $fieldsProcessed)) {
- $form->addChainSelect($name, array('label' => $title, 'required' => $required));
- }
- else {
- $options = CRM_Core_PseudoConstant::stateProvince();
- $form->add('select', $name, $title, $options, $required && $options, $selectAttributes);
- }
+ $form->addChainSelect($name, array('label' => $title, 'required' => $required));
$config = CRM_Core_Config::singleton();
if (!in_array($mode, array(
CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) &&
}
elseif (substr($fieldName, 0, 6) === 'county') {
if ($addressOptions['county']) {
- $controlField = str_replace('county', 'state_province', $name);
- if (isset($form->_fields[$controlField]) || in_array($controlField, $fieldsProcessed)) {
- $form->addChainSelect($name, array('label' => $title, 'required' => $required));
- }
- else {
- $options = CRM_Core_PseudoConstant::county();
- $form->add('select', $name, $title, $options, $required && $options, $selectAttributes);
- }
+ $form->addChainSelect($name, array('label' => $title, 'required' => $required));
}
}
elseif (substr($fieldName, 0, 9) === 'image_URL') {
'placeholder' => empty($settings['required']) ? ts('- none -') : ts('- select -'),
);
CRM_Utils_Array::remove($props, 'label', 'required', 'control_field');
- $props['class'] = (empty($props['class']) ? '' : "{$props['class']} ") . 'crm-chain-select-target crm-select2';
+ $props['class'] = (empty($props['class']) ? '' : "{$props['class']} ") . 'crm-select2';
$props['data-select-prompt'] = $props['placeholder'];
$props['data-name'] = $elementName;
*/
private function preProcessChainSelectFields() {
foreach ($this->_chainSelectFields as $control => $target) {
- $controlField = $this->getElement($control);
$targetField = $this->getElement($target);
- $controlType = $targetField->getAttribute('data-callback') == 'civicrm/ajax/jqCounty' ? 'stateProvince' : 'country';
-
- $css = (string) $controlField->getAttribute('class');
- $controlField->updateAttributes(array(
- 'class' => ($css ? "$css " : 'crm-select2 ') . 'crm-chain-select-control',
- 'data-target' => $target,
- ));
- $controlValue = $controlField->getValue();
+ $targetType = $targetField->getAttribute('data-callback') == 'civicrm/ajax/jqCounty' ? 'county' : 'stateProvince';
$options = array();
- if ($controlValue) {
- $options = CRM_Core_BAO_Location::getChainSelectValues($controlValue, $controlType, TRUE);
- if (!$options) {
- $targetField->setAttribute('placeholder', $targetField->getAttribute('data-none-prompt'));
+ // If the control field is on the form, setup chain-select and dynamically populate options
+ if ($this->elementExists($control)) {
+ $controlField = $this->getElement($control);
+ $controlType = $targetType == 'county' ? 'stateProvince' : 'country';
+
+ $targetField->setAttribute('class', $targetField->getAttribute('class') . ' crm-chain-select-target');
+
+ $css = (string) $controlField->getAttribute('class');
+ $controlField->updateAttributes(array(
+ 'class' => ($css ? "$css " : 'crm-select2 ') . 'crm-chain-select-control',
+ 'data-target' => $target,
+ ));
+ $controlValue = $controlField->getValue();
+ if ($controlValue) {
+ $options = CRM_Core_BAO_Location::getChainSelectValues($controlValue, $controlType, TRUE);
+ if (!$options) {
+ $targetField->setAttribute('placeholder', $targetField->getAttribute('data-none-prompt'));
+ }
+ } else {
+ $targetField->setAttribute('placeholder', $targetField->getAttribute('data-empty-prompt'));
+ $targetField->setAttribute('disabled', 'disabled');
}
}
+ // Control field not present - fall back to loading default options
else {
- $targetField->setAttribute('placeholder', $targetField->getAttribute('data-empty-prompt'));
- $targetField->setAttribute('disabled', 'disabled');
+ $options = CRM_Core_PseudoConstant::$targetType();
}
if (!$targetField->getAttribute('multiple')) {
$options = array('' => $targetField->getAttribute('placeholder')) + $options;