-
Notifications
You must be signed in to change notification settings - Fork 631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
anchor summary error to field for nested matrix "blocks" #15811
base: 5.x
Are you sure you want to change the base?
anchor summary error to field for nested matrix "blocks" #15811
Conversation
It’s expected that recursively-nested fields will get error attribute prefixes that reveal the full path to the element. For example, locally I have a required Entries field that is nested in two parent Matrix entries, and when I save it without a value, the top-level entry gets an error with the following key:
With this PR, the error’s key is only:
Which leaves out critical information, as the top-level entry doesn’t know anything about an |
Thanks for the chat on this one, @brandonkelly! I reverted the previous change and used a different approach. |
$layoutElement->getField() instanceof Matrix && | ||
$layoutElement->getField()->viewMode === Matrix::VIEW_MODE_BLOCKS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@i-just Do you think it would be save to skip this check, so the same thing works for Neo? If it’s a Matrix field in cards/index view, then there won’t be any inputs to match for the error anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested that, and it won’t affect Neo.
Neo still uses block indexes when prefixing model errors (switching to $block->uid
makes the prefix look as expected).
They’re also not using errorKeyPrefix
when rendering the blocks form, which means the error key is set to just the handle of the individual field (e.g. myPlainTextField
). Passing {'errorKeyPrefix' : "#{handle}[#{block.uid}]"}
as the 3rd param prefixes the errors as expected.
With those two changes in place, anchoring to erroring fields inside Neo works as expected, and the lines you mentioned don’t affect that.
Description
For a matrix in a matrix where the view mode is set to inline-editable blocks, we need to continue to rewrite the errors all the way up to the element that contains the first inline matrix field. However, when adding a prefix to errors in the summary, we need to ensure only the immediate owner prefix is added. That way, we’re able to reliably anchor from the error summary to the affected field.
Related issues
#15797