5465: restore submit buttons when duplicate-item modal is dismissed#5575
Open
mvanhorn wants to merge 1 commit into
Open
5465: restore submit buttons when duplicate-item modal is dismissed#5575mvanhorn wants to merge 1 commit into
mvanhorn wants to merge 1 commit into
Conversation
The duplicate-detection modal in audit_duplicates_controller intercepts the submit event with preventDefault and shows a Bootstrap modal. Dismissing the modal with 'Make Changes' or the close button never triggers a real form submission, so any submit button left in a UJS "Saving" / "disabled" state by handlers that fire before our submit listener has nothing to restore it. Snapshot every submit button in the form when the modal opens, and on hidden.bs.modal (when the user dismissed without merging) restore each button's disabled flag plus its visible text. The merge path is exempt from the restore because mergeAndSubmit actually submits the form and the page transitions away.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Resolves #5465.
What
When the duplicate-item detection modal in
audit_duplicates_controlleropens, the form's submit buttons can already have been disabled and re-labelled "Saving" by Rails UJS (or another delegated handler that fires before the Stimulussubmitlistener gets to callpreventDefault). Today, dismissing the modal via "Make Changes" or the close button never triggers a real form submission, so nothing restores those buttons — they stay disabled with the "Saving" label.The existing fix in connect() (strip
data-disable-with+data-remote) didn't fully cover this because:data-confirmflow can mark the button disabled as part of the re-dispatched click.disabledon submit would slip past the attribute strip without us noticing.How
showModalnow snapshots each submit button'sdisabledflag and visible text when the modal opens. Onhidden.bs.modal(single-use listener), if the user dismissed without going throughmergeAndSubmit, restore the snapshotted values. The merge path is exempt becausemergeAndSubmitactually submits the form and the page transitions away.Verification
js: trueaudit-duplicates system spec atspec/system/audit_system_spec.rb:199still exercises the merge path; the restore branch is the dismissal path so behaviour there is unchanged.AI was used for assistance.