From b77d7f98c64edda4d49b2415e092e804e4c37e70 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 14 Jul 2023 14:21:05 -0400 Subject: [PATCH] Add null argument option to InputfieldForm::getErrors(null) which adds support for clearing internal errors cache --- wire/modules/Inputfield/InputfieldForm.module | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/wire/modules/Inputfield/InputfieldForm.module b/wire/modules/Inputfield/InputfieldForm.module index a10b9df9..783676fa 100644 --- a/wire/modules/Inputfield/InputfieldForm.module +++ b/wire/modules/Inputfield/InputfieldForm.module @@ -679,12 +679,19 @@ class InputfieldForm extends InputfieldWrapper { * * #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 * */ 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); $this->errorCache = $clear ? null : $errors; return $errors; @@ -714,4 +721,3 @@ class InputfieldForm extends InputfieldWrapper { protected function ___renderOrProcessReady($type) { } } -