/** * Validate country / state / county match and suppress unwanted "required" errors */ private function validateChainSelectFields() { foreach ($this->_chainSelectFields as $control => $target) { if ($this->elementExists($control) && $this->elementExists($target)) { $controlValue = (array) $this->getElementValue($control); $targetField = $this->getElement($target); $controlType = $targetField->getAttribute('data-callback') == 'civicrm/ajax/jqCounty' ? 'stateProvince' : 'country'; $targetValue = array_filter((array) $targetField->getValue()); if ($targetValue || $this->getElementError($target)) { $options = CRM_Core_BAO_Location::getChainSelectValues($controlValue, $controlType, TRUE); if ($targetValue) { if (!array_intersect($targetValue, array_keys($options))) { $this->setElementError($target, $controlType == 'country' ? ts('State/Province does not match the selected Country') : ts('County does not match the selected State/Province')); } } elseif (!$options) { $this->setElementError($target, NULL); } } } } }
public static function jqCounty() { CRM_Utils_JSON::output(CRM_Core_BAO_Location::getChainSelectValues($_GET['_value'], 'stateProvince')); }