From cf8013191011328f319dc8d21fc7349e9fdb0b25 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Fri, 22 Sep 2023 12:30:35 +0200 Subject: [PATCH] mvc: BooleanField validation message and faulty regex fix --- .../OPNsense/Base/FieldTypes/BooleanField.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BooleanField.php b/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BooleanField.php index e92bc285c..060266744 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BooleanField.php +++ b/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BooleanField.php @@ -42,9 +42,12 @@ class BooleanField extends BaseField protected $internalIsContainer = false; /** - * @var string default validation message string + * {@inheritdoc} */ - protected $internalValidationMessage = "value should be a boolean (0,1)"; + protected function defaultValidationMessage() + { + return gettext('Value should be a boolean (0,1).'); + } /** * retrieve field validators for this field type @@ -52,13 +55,12 @@ class BooleanField extends BaseField */ public function getValidators() { - // regexp for validating boolean values. - $regex_mask = "/^([0,1]){1}$/"; - $validators = parent::getValidators(); if ($this->internalValue != null) { - $validators[] = new Regex(array('message' => $this->internalValidationMessage, - 'pattern' => trim($regex_mask))); + $validators[] = new Regex([ + 'message' => $this->getValidationMessage(), + 'pattern' => '/^[01]$/', + ]); } return $validators; }