0

I have a problem with a form inside a modal.

Here is my form

<%= form_tag({controller: "controller", action: "action"}, id: "form_id", remote: true) do %>
   <button class="btn btn-default btn-xs btn-filter" id="id_button">
   <%= number_field_tag "id", nil, placeholder: "0", class: "input_class" %>
   <%= submit_tag("ok", id: "submit_add", class: "btn btn-success") %>
<% end %>

The submit tag works well, but jquery-ujs adds this event:

function(event) {
  var button = $(this);

  if (!rails.allowAction(button)) return rails.stopEverything(event);


  // register the pressed submit button
  var name = button.attr('name'),
  data = name ? {
  name: name,
  value: button.val()
} : null;

button.closest('form').data('ujs:submit-button', data);
}

on the button identified by #id_button, which causes that button to also submit the form, but I don't want that.

I found nothing about this problem.

Cyril Duchon-Doris
  • 12,964
  • 9
  • 77
  • 164
J.leduc
  • 13
  • 2

1 Answers1

2

The default behavior of a button in HTML is to submit the form.

If you want a different type of action, you need to specify type="button" inside thebutton tag. This has nothing to do with jquery-ujs I'm afraid.

<button type="button" class="btn btn-default btn-xs btn-filter" id="id_button">
Cyril Duchon-Doris
  • 12,964
  • 9
  • 77
  • 164