You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The button_tag will trigger the UJS driver only when the button's type='submit'.
For example, if I want to generate a delete button with confirmation I could do:
button_tag "Delete", data: { confirm: "Are you sure you want to delete this resource?"}
However, I want to use a button with confirmation to delete a nested resource on the main resource's form, but if I use the above method, the button's type is 'submit' so it immediately submits the form after confirmation. That is not desirable.
I would like to use:
button_tag type: 'button', data: { confirm: "Are you sure you want to delete this resource?"}
However, because the button type is 'button' and not 'submit', the UJS driver isn't triggered, thus no confirmation is shown.
It seems to me that the UJS driver should pick up anything that has data-confirm (and data-disable, for that matter), instead of only activating for 'submit' buttons.
Is this by design or is this something that should be changed?
@rafaelfranca Thanks for migrating this, I probably should have thought about which repo to post this to, but I only had 5 minutes to think about it before class.
@rafaelfranca I'm hitting this same issue this morning (trying to add data-confirm to a reset button in a form), and would be happy to work on a fix.
From the maintainers' perspective, does it work to modify the formInputClickSelector to catch buttons of anytype that are in a form, or would this introduce other issues?
From @cireficc on September 9, 2015 15:29
The
button_tag
will trigger the UJS driver only when the button'stype='submit'
.For example, if I want to generate a delete button with confirmation I could do:
button_tag "Delete", data: { confirm: "Are you sure you want to delete this resource?"}
However, I want to use a button with confirmation to delete a nested resource on the main resource's form, but if I use the above method, the button's type is
'submit'
so it immediately submits the form after confirmation. That is not desirable.I would like to use:
button_tag type: 'button', data: { confirm: "Are you sure you want to delete this resource?"}
However, because the button type is
'button'
and not'submit'
, the UJS driver isn't triggered, thus no confirmation is shown.It seems to me that the UJS driver should pick up anything that has
data-confirm
(anddata-disable
, for that matter), instead of only activating for'submit'
buttons.Is this by design or is this something that should be changed?
Copied from original issue: rails/rails#21564
The text was updated successfully, but these errors were encountered: