1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-09 00:06:55 +02:00

Add null argument option to InputfieldForm::getErrors(null) which adds support for clearing internal errors cache

This commit is contained in:
Ryan Cramer
2023-07-14 14:21:05 -04:00
parent 67b6f5817b
commit b77d7f98c6

View File

@@ -679,12 +679,19 @@ class InputfieldForm extends InputfieldWrapper {
* *
* #pw-group-errors * #pw-group-errors
* *
* @param bool $clear Specify true to clear out the errors (default=false). * @param bool|null $clear Clear or re-check for errors? (default=false)
* - Specify `true` to clear out the errors.
* - Specify `false` or omit the argument to neither clear or uncache errors. (default)
* - Specify `null` to uncache a previous call and re-check all fields in the form. (3.0.223+)
* @return array Array of error strings * @return array Array of error strings
* *
*/ */
public function getErrors($clear = false) { public function getErrors($clear = false) {
if($this->errorCache !== null) return $this->errorCache; if($clear === null) {
$this->errorCache = null;
$clear = false;
}
if($this->errorCache !== null && $clear === false) return $this->errorCache;
$errors = parent::getErrors($clear); $errors = parent::getErrors($clear);
$this->errorCache = $clear ? null : $errors; $this->errorCache = $clear ? null : $errors;
return $errors; return $errors;
@@ -714,4 +721,3 @@ class InputfieldForm extends InputfieldWrapper {
protected function ___renderOrProcessReady($type) { protected function ___renderOrProcessReady($type) {
} }
} }