1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-23 23:02:58 +02:00

Make Inputfield requiredLabel customizable per field from API via $inputfield->requiredLabel property, to provide option to override default "missing requird value" label.

This commit is contained in:
Ryan Cramer
2018-04-06 06:56:54 -04:00
parent f27feb2bbf
commit c5147a5279
3 changed files with 7 additions and 2 deletions

View File

@@ -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

View File

@@ -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);
}
}

View File

@@ -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)");
}