From: Coleman Watts Date: Wed, 22 Oct 2014 18:27:38 +0000 (-0400) Subject: CRM-15476 - Only validate chainSelect fields if the control field exists X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=14b2ff1521a8c25e363b13723c2979f52ad1cd47;p=civicrm-core.git CRM-15476 - Only validate chainSelect fields if the control field exists --- diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index d805d59f8c..f328e17fe7 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -1806,21 +1806,22 @@ class CRM_Core_Form extends HTML_QuickForm_Page { */ private function validateChainSelectFields() { foreach ($this->_chainSelectFields as $control => $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')); + if ($this->elementExists($control)) { + $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')); + } + } // Suppress "required" error for field if it has no options + elseif (!$options) { + $this->setElementError($target, NULL); } } - // Suppress "required" error for field if it has no options - elseif (!$options) { - $this->setElementError($target, NULL); - } } } }