问题描述:

The two simple forms I have looks like this:

= simple_form_for(@class_room, :html=>{:id=>'class_room_form'}) do |class_room_form|

and

= simple_form_for(@lesson, :html => {:id=>'lesson_form'}) do |lesson_form|

now, although I am submitting form of id lesson_form, form with id class_room_form is submitted instead! any idea what to do ?

here is how I submit the lesson_form form:

:javascript

$('#submit_lesson_button').bind('click', function() {

$("#lesson_form").trigger('submit');

});

here is how I submit the other form ( the one that is still submitted regardlessly )

:javascript

$('#submit_button').bind('click', function() {

$('#sidenav a:first').tab('show');

$('#class_room_form').trigger('submit');

});

you see, each form with different ids, and I am targeting those different ids with jQuery, so what could be wrong ??

notice that form lesson_form is contained within form class_room_form

网友答案:

You're not supposed to have a form contained is another form. If you can change this, it will certainly solve your problem, and your code will be cleaner.

If you can't, try to add event.preventDefault() to your functions, like this :

:javascript
  $('#submit_lesson_button').bind('click', function(event) {
    event.preventDefault();
    $("#lesson_form").trigger('submit');
  });

:javascript
  $('#submit_button').bind('click', function() {
    event.preventDefault();
    $('#sidenav a:first').tab('show');
    $('#class_room_form').trigger('submit');
  });

I suppose #submit_lesson_button and #submit_button are <input type="submit" ... >

相关阅读:
Top