From 14b2ff1521a8c25e363b13723c2979f52ad1cd47 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 22 Oct 2014 14:27:38 -0400 Subject: [PATCH] CRM-15476 - Only validate chainSelect fields if the control field exists --- CRM/Core/Form.php | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) 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); - } } } } -- 2.25.1