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_to data-confirm shows confirmation twice, but does not send the form #467

Open
phillipp opened this issue Mar 30, 2016 · 5 comments

Comments

@phillipp
Copy link

Hi,
I'm using the button_to like this:

=button_to example_path, class: 'btn btn-danger', data: { confirm: 'Really?' } do
  %i.icon-undo
  Example Text

Now I expected that it would ask the confirmation once and submit the form. What happens instead is that the confirmation shows up twice and the form is not submitted.

Looking at the stack traces I saw that events for two different selectors: formInputClickSelector and buttonClickSelector

The confirmation prompt is then called from lines 383 and 447 respectively. I dont understand how the original control flow should look like, but maybe there is an easy fix? I would be happy to submit a PR if you could give me a hint where to look at.

@phillipp
Copy link
Author

Oh, jquery-rails is 3.1.4, btw.

@mctaylorpants
Copy link

If you're looking to submit the form after a confirmation, I recommend using the submit_tag helper instead. A button within a form won't submit the form (unless its type is set to "submit" or you use Javascript).

@phillipp
Copy link
Author

phillipp commented Jun 27, 2016

@alextaylor000 button_to generates form with a <input type="submit"> - so your comment does not really make any sense... or I am missing something here?

@mctaylorpants
Copy link

@phillipp Oops, apologies, I assumed you were using it explicitly within another form element.

It looks like this issue has been fixed in the latest version (see this commit which made the button click listeners more explicit). I just verified the expected behaviour in my environment.

@randall-coding
Copy link

randall-coding commented Jul 29, 2020

I still get this issue of two dialog boxes. Here is my code.

  <%= form_for :interview_template, url:interview_template_path(@interview_template.id), method: :patch do |f|  %>
        <%= f.hidden_field :reviewed, value:true %>
        <%= f.submit "Complete Question Review", class: "button primary-button", data:{confirm:"Mark review as complete?"} %>
      <% end %>

The above when clicked shows a dialog, I click OK, then it shows up the second time.
If I click cancel on the first dialog it only shows up once.

Rails 6.0 jquery-rails 4.3.5

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