Show the correct tab for subfield errors #5690
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
WHY
To correctly detect the crud fieldName for subfields with validation errors and display the relevant tab to maintain consistency with the behaviour of other fields that have validation errors.
BEFORE - What was wrong? What was happening before this PR?
When the first error is on a subfield, I expect that tab to be the active tab as it would be with other fields.
Because the fieldname is in dot notation array format, this does not match the crud fieldname e.g. someRelation.0.name does not match the fieldName someRelation, therefore the error is skipped when determining the tab to activate
AFTER - What is happening after this PR?
The crud fieldName is parsed from the current field under test and will match the parent fieldName, allowing it to set the active tab appropriately.
HOW
How did you achieve that, in technical terms?
I stripped the crud fieldName from the start of the subfield name
$fieldName = preg_split('/\.\d+\./',$fieldName)[0];
Is it a breaking change?
No
How can we test the before & after?
Create a validation error on a subfield that is not on the first tab.
Before: the errors are shown, but the subfield's tab is not active.
After: The tab with the subfield is the active tab.