Rails Trying to submit a form onchange of dropdown

后端 未结 11 1258
遥遥无期
遥遥无期 2020-12-13 20:28

I have my Ajax working, builtin Rails javascript, with the submit button. However, I would like it to submit when I change the value of the dropdown box and eliminate the b

11条回答
  •  独厮守ぢ
    2020-12-13 21:12

    This seems to have been around for a while but, I'll post my findings anyway since I haven't found this explanation anywhere yet.

    I came across this article which describes quite well what's the problem when triggering a ajax request via the submit() method (with or without jQuery or Handler). The author then recommends to form your own AJAX request. That is not required and shouldn't be done to make use of the logic within rails.js (jquery-jus gem).

    Problems with triggering submit() manually occur since rails.js binds and listens to an event that is namespaced submit.rails. To manually trigger a submission use

       onchange: 'javascript: $( this ).trigger("submit.rails")'
    

    on the element or the form.

提交回复
热议问题