Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

button_tag doesn't trigger UJS driver unless it type='submit' #437

Open
rafaelfranca opened this issue Sep 9, 2015 · 2 comments
Open

button_tag doesn't trigger UJS driver unless it type='submit' #437

rafaelfranca opened this issue Sep 9, 2015 · 2 comments

Comments

@rafaelfranca
Copy link
Member

From @cireficc on September 9, 2015 15:29

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?

Copied from original issue: rails/rails#21564

@cireficc
Copy link

cireficc commented Sep 9, 2015

@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.

@nathancarnes
Copy link

@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 any type that are in a form, or would this introduce other issues?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants