Make data-turbo-confirm work with multiple submitters inside a form #564
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 pull request makes so that you can use different
data-turbo-confirm
on each submitter inside your form, instead of allowing only onedata-confirm
per form.Problem: If you're nested inside a form, you can't use
button_to
because you'd end up with a nested form, which is invalid and discarded by the browser.So, how one would accomplish a UI like the following?
That delete button is inside a form. A
button_to
there isn't allowed.However, as @seanpdoyle greatly points here, the browser spec allows you to change the default
action
andmethod
of the form on the submitter, by usingformaction
andformmethod
attributes on the button itself.So you could go for this:
And you're done. Turbo will submit the form with the correct DELETE verb, to the correct
destroy_all_empty_path
, will automatically disable the submitter and, with the clever CSS we already know, we can show a loading state on the button.There was only one piece missing, which this pull request addresses: the
data-turbo-confirm
currently doesn't work on that button, because the code only looks at the encompassingform
data-turbo-confirm
.We now will look first to the
data-turbo-confirm
of the form submitter and show it instead of the form's if it's present.