From c5147a5279b71aea4d7f6030c213b85552f09bdd Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 6 Apr 2018 06:56:54 -0400 Subject: [PATCH] Make Inputfield requiredLabel customizable per field from API via $inputfield->requiredLabel property, to provide option to override default "missing requird value" label. --- wire/core/Inputfield.php | 1 + wire/core/InputfieldWrapper.php | 4 +++- wire/modules/Inputfield/InputfieldForm.module | 4 +++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/wire/core/Inputfield.php b/wire/core/Inputfield.php index 5d708776..fe337618 100644 --- a/wire/core/Inputfield.php +++ b/wire/core/Inputfield.php @@ -51,6 +51,7 @@ * @property string $description Optional description that appears under label to provide more detailed information. #pw-group-labels * @property string $notes Optional notes that appear under input area to provide additional notes. #pw-group-labels * @property string $icon Optional font-awesome icon name to accompany label (excluding the "fa-") part). #pw-group-labels + * @property string $requiredLabel Optional custom label to display when missing required value. @since 3.0.98 #pw-group-labels * @property string $head Optional text that appears below label but above description (only used by some Inputfields). #pw-internal * @property string|null $prependMarkup Optional markup to prepend to the Inputfield content container. #pw-group-other * @property string|null $appendMarkup Optional markup to append to the Inputfield content container. #pw-group-other diff --git a/wire/core/InputfieldWrapper.php b/wire/core/InputfieldWrapper.php index 66d0a19f..09f75239 100644 --- a/wire/core/InputfieldWrapper.php +++ b/wire/core/InputfieldWrapper.php @@ -795,7 +795,9 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre // check if a value is required and field is empty, trigger an error if so if($child->name && $child->getSetting('required') && $child->isEmpty()) { - $child->error($this->requiredLabel); + $requiredLabel = $child->getSetting('requiredLabel'); + if(empty($requiredLabel)) $requiredLabel = $this->requiredLabel; + $child->error($requiredLabel); } } diff --git a/wire/modules/Inputfield/InputfieldForm.module b/wire/modules/Inputfield/InputfieldForm.module index 31938fd9..d473f872 100644 --- a/wire/modules/Inputfield/InputfieldForm.module +++ b/wire/modules/Inputfield/InputfieldForm.module @@ -362,7 +362,9 @@ class InputfieldForm extends InputfieldWrapper { if($required) { if($child->isEmpty()) { if(self::debug) $this->debugNote("$child->name - determined that value IS required and is not present (error)"); - $child->error($this->requiredLabel); // requiredLabel from InputfieldWrapper + $requiredLabel = $child->getSetting('requiredLabel'); + if(empty($requiredLabel)) $requiredLabel = $this->requiredLabel; // requiredLabel from InputfieldWrapper + $child->error($requiredLabel); } else { if(self::debug) $this->debugNote("$child->name - determined that value IS required and is populated (good)"); }