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.
This commit is contained in:
Franco Fichtner 2023-09-21 08:14:13 +02:00
parent e5cbf948a1
commit bcd8cec574

View File

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