How to auto-submit Rails formhelper, when onchange occurs on select dropdown (populated from DB)

后端 未结 1 422
星月不相逢
星月不相逢 2021-01-13 07:50

I have a form in my View with two dropdowns, both populated from db tables, where I\'d like to auto-submit the form when onchange event occurs on either dropdown:

         


        
相关标签:
1条回答
  • 2021-01-13 08:31

    See documentation: http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-select

    The arguments goes like this:

    select(object, method, choices, options = {}, html_options = {})
    

    :onchange belongs to html options thus you need to fix your select box to this:

    select('post', 'state', @suppliers.collect {|s| [s.supp_state, s.id]}, :onchange => "this.form.submit()")
    
    0 讨论(0)
提交回复
热议问题