mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
Add support for checking if nested form fields are required for visual indicator
This commit is contained in:
parent
787c2244bf
commit
fcec026dff
@ -837,6 +837,24 @@ class Form extends WidgetBase
|
||||
*/
|
||||
if ($field->required === null && $this->model && method_exists($this->model, 'isAttributeRequired')) {
|
||||
$fieldName = implode('.', HtmlHelper::nameToArray($field->fieldName));
|
||||
|
||||
// Check nested fields
|
||||
if ($this->isNested) {
|
||||
// Get the current attribute level
|
||||
$nameArray = HtmlHelper::nameToArray($this->arrayName);
|
||||
unset($nameArray[0]);
|
||||
|
||||
// Convert any numeric indexes to wildcards
|
||||
foreach ($nameArray as $i => $value) {
|
||||
if (preg_match('/^[0-9]*$/', $value)) {
|
||||
$nameArray[$i] = '*';
|
||||
}
|
||||
}
|
||||
|
||||
// Recombine names for full attribute name in rules array
|
||||
$fieldName = implode('.', $nameArray) . ".{$fieldName}";
|
||||
}
|
||||
|
||||
$field->required = $this->model->isAttributeRequired($fieldName);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user