mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 12:40:01 +01:00
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:
parent
4d0ac716bc
commit
f8c31abad0
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user