button_to data-confirm shows confirmation twice, but does not send the form
phillipp opened this issue · 5 comments
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.
Oh, jquery-rails is 3.1.4, btw.
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).
@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?
@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.
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