The reason why you couldn't find holder-required
is because it technically doesn't exist in the SilverStripe codebase, it actually is a class that is concatenated together from two strings.
In a FormField
, there is a function called "extraClass" which adds these classes to the field.
Below is the snippet of code from the FormField
class:
public function extraClass() {
$classes = array();
$classes[] = $this->Type();
if($this->extraClasses) {
$classes = array_merge(
$classes,
array_values($this->extraClasses)
);
}
if(!$this->Title()) {
$classes[] = 'nolabel';
}
// Allow custom styling of any element in the container based on validation errors,
// e.g. red borders on input tags.
//
// CSS class needs to be different from the one rendered through {@link FieldHolder()}.
if($this->Message()) {
$classes[] .= 'holder-' . $this->MessageType();
}
return implode(' ', $classes);
}
What this tells us is that for a message that appears for a field, it will append holder-{Whatever_Your_Message_Type_Is}
as an extra class.
The reason why $this->Message()
would still be set after a page reload is that the error information is actually saved to the session for that form.
Below is a snippet from the Form
class which is what calls the FormField::setError()
, the function that sets the message property on the form field.
public function setupFormErrors() {
$errorInfo = Session::get("FormInfo.{$this->FormName()}");
if(isset($errorInfo['errors']) && is_array($errorInfo['errors'])) {
foreach($errorInfo['errors'] as $error) {
$field = $this->fields->dataFieldByName($error['fieldName']);
if(!$field) {
$errorInfo['message'] = $error['message'];
$errorInfo['type'] = $error['messageType'];
} else {
$field->setError($error['message'], $error['messageType']);
}
}
// load data in from previous submission upon error
if(isset($errorInfo['data'])) $this->loadDataFrom($errorInfo['data']);
}
if(isset($errorInfo['message']) && isset($errorInfo['type'])) {
$this->setMessage($errorInfo['message'], $errorInfo['type']);
}
return $this;
}
I've had a bit more of a browse of the Form
code, it should be clearing the errors after it is rendering the form. There are two functions part of the form class, clearMessage
and resetValidation
.
The function clearMessage
is called when rendering the form template through forTemplate
. I do not see any usage of the resetValidation
function throughout the SilverStripe CMS or Framework codebases.
You may need to potentially call one or the other in your code if under your circumstances the message is not clearing.