Set validation attributes after context check.

This prevent fields with multiple contexts from overwriting the label name of another context in the validation messages.

Fixes https://github.com/rainlab/user-plugin/issues/371.
This commit is contained in:
Ben Thomson 2019-07-26 00:27:45 +08:00
parent df81ea182b
commit 610e0c383c
No known key found for this signature in database
GPG Key ID: B2BAFACC5ED68F87
1 changed files with 9 additions and 12 deletions

View File

@ -688,9 +688,7 @@ class Form extends WidgetBase
$fieldObj = $this->makeFormField($name, $config);
$fieldTab = is_array($config) ? array_get($config, 'tab') : null;
/*
* Check that the form field matches the active context
*/
// Check that the form field matches the active context
if ($fieldObj->context !== null) {
$context = is_array($fieldObj->context) ? $fieldObj->context : [$fieldObj->context];
if (!in_array($this->getContext(), $context)) {
@ -698,6 +696,13 @@ class Form extends WidgetBase
}
}
// Apply the field name to the validation engine
$attrName = implode('.', HtmlHelper::nameToArray($fieldObj->fieldName));
if ($this->model && method_exists($this->model, 'setValidationAttributeName')) {
$this->model->setValidationAttributeName($attrName, $fieldObj->label);
}
$this->allFields[$name] = $fieldObj;
switch (strtolower($addToArea)) {
@ -794,6 +799,7 @@ class Form extends WidgetBase
$field->context = $fieldContext;
}
$attrName = implode('.', HtmlHelper::nameToArray($field->fieldName));
$field->arrayName = $this->arrayName;
$field->idPrefix = $this->getId();
@ -836,15 +842,6 @@ class Form extends WidgetBase
*/
$field->value = $this->getFieldValue($field);
/*
* Apply the field name to the validation engine
*/
$attrName = implode('.', HtmlHelper::nameToArray($field->fieldName));
if ($this->model && method_exists($this->model, 'setValidationAttributeName')) {
$this->model->setValidationAttributeName($attrName, $field->label);
}
/*
* Check model if field is required
*/