From bcd8cec574196be8ca6c24df941c192a588c37a4 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Thu, 21 Sep 2023 08:14:13 +0200 Subject: [PATCH] mvc: emit correct message on required validation in BaseField The base field would emit the validation message of the derived field, but that is strange sometimes since the actual reason is much more simple and less ambiguous. Also makes it able to trace the error to the model definition of Required=Y instead of routing it through a different field that may have had no say in this. Noticed on pools name input that throws "text validation error", but was really complaining about the lack of a value. --- .../mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php b/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php index 82d876a67..c42c89ce0 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php +++ b/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php @@ -519,6 +519,7 @@ abstract class BaseField } return $result; } + /** * return field validators for this field * @return array returns validators for this field type (empty if none) @@ -527,7 +528,7 @@ abstract class BaseField { $validators = $this->getConstraintValidators(); if ($this->isEmptyAndRequired()) { - $validators[] = new PresenceOf(array('message' => $this->internalValidationMessage)); + $validators[] = new PresenceOf(['message' => gettext('A value is required.')]); } return $validators; } @@ -580,7 +581,6 @@ abstract class BaseField return $result; } - /** * get nodes as array structure * @return array @@ -608,7 +608,6 @@ abstract class BaseField return (string)$this; } - /** * update model with data returning missing repeating tag types. * @param $data array structure containing new model content @@ -642,7 +641,6 @@ abstract class BaseField } } - /** * Add this node and its children to the supplied simplexml node pointer. * @param SimpleXMLElement $node target node