mvc: BooleanField validation message and faulty regex fix

This commit is contained in:
Franco Fichtner 2023-09-22 12:30:35 +02:00
parent 3363fa9d2d
commit cf80131910

View File

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