Rails: submit (via AJAX) when drop-down option clicked

后端 未结 5 2062
礼貌的吻别
礼貌的吻别 2021-02-04 10:14

What is the easiest and most graceful way to auto-submit an AJAX form when a drop-down box\'s option is selected? I\'m creating an administration page where the admin can modify

5条回答
  •  不知归路
    2021-02-04 11:09

    I am using Rails 5 & I was also facing the similar situation but in my case the answer given by @scott was not submitting the form using AJAX as expected though I added the remote: true option to the form (I don't have submit button in the form).

    If somebody is also facing the similar problem try to change the JS code like this-

    <% form_for membership remote: true, id: '#member_form' do |f| %>
      <%= f.select :permissions, [['none', 0], ['admin', 9]], onchange: '$("#member_form").trigger("submit");' %>
    <% end %>
    

    Hope this helps..

提交回复
热议问题