[4.x] Reveal invalid field on validation error #9577
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.
This PR makes a small UX improvement by revealing the first (and most nested) invalid field in the publish form when a validation error occurs, which is particularly useful in large forms with lots of tabs/sets. It will automatically expand sets, activate the right tab then scroll to the field:
CleanShot.2024-02-23.at.15.18.21.mp4
The logic is mostly DOM based with a few hooks into the Vue components to update active/expanded state. It's implemented as a new plugin that can be called via
this.$reveal
orStatamic.$reveal
.A new global helper function called
closestVm
is included that will take a DOM node and return the nearest Vue component, optionally matching a specific component name. The replicator and bard set components are now being registered so that they have names, which was required in order to make the lookup work. Additionally a newtab-handle
data attribute has been added to tab panel elements in order to make the tab activation simpler.The feature has been added to the entry, term and user publish forms.