Rails Trying to submit a form onchange of dropdown

后端 未结 11 1289
遥遥无期
遥遥无期 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

    If you want to learn rails way ajax submit on fields change here is the code.

    <%= select_tag(:id, options_from_collection_for_select(active_cars, "id", "name"), 
    data: { remote: true, url: your_ajax_route_path }%><%= submit_tag "Switch Car" %>
    

    data: { remote: true, url: your_ajax_route_path }

    will automatically submit your input to your_ajax_route_path. If you are using a form builder then you should use with input_html

    input_html: { data: { remote: true, url: your_ajax_route_path } }
    

    like this. I hope it'll be useful for you

提交回复
热议问题