MDL-53140 forms: Implement validateSubmitValue for the group element

The group element needs to call validateSubmitValue() for all of its
containing elements.
This commit is contained in:
Shamim Rezaie 2019-02-01 19:44:06 +11:00
parent 4d0ac716bc
commit f8c31abad0

View File

@ -257,4 +257,22 @@ class MoodleQuickForm_group extends HTML_QuickForm_group implements templatable
}
$renderer->finishGroup($this);
}
/**
* Calls the validateSubmitValue function for the containing elements and returns an error string as soon as it finds one.
*
* @param array $values Values of the containing elements.
* @return string|null Validation error message or null.
*/
public function validateSubmitValue($values) {
foreach ($this->_elements as $element) {
if (method_exists($element, 'validateSubmitValue')) {
$value = $values[$element->getName()] ?? null;
$result = $element->validateSubmitValue($value);
if (!empty($result) && is_string($result)) {
return $result;
}
}
}
}
}