javascript - Ransack submit form onchange of select box -


using ransack, have simple dropdown filtering list. working ok, need press submit button.

i'd action of changing dropdown submit search_form_for

<%= search_form_for @query |f| %>      <%= f.select :category_eq, options_for_select(article::categories.sort.map {|k,v| [v,k]}), include_blank: true, onchange: "this.form.submit();" %>      <%= f.submit  %> <% end %> 

the onchange doesn't work

onchange: "this.form.submit();" 

edit

the onchange doesn't appear in rendered form

 <form class="article_search" id="article_search" action="/articles" accept-charset="utf-8" method="get"><input name="utf8" type="hidden" value="✓">         <select name="q[category_eq]" id="q_category_eq"><option value=""></option> <option value="caffe">caffe</option> <option value="data_mining">data mining</option> <option value="deep_learning">deep learning</option>           <input type="submit" name="commit" value="search"> 

edit 2

it looks search_form_for passes options form_for

https://github.com/activerecord-hackery/ransack/blob/26cb9e4210fd1728f266ea40095ed6093ca4a994/lib/ransack/helpers/form_helper.rb#l34

html options hash should passed separate parameter. more information here: http://apidock.com/rails/actionview/helpers/formoptionshelper/select

you can try:

<%= f.select :category_eq, ..., { include_blank: true }, { onchange: 'this.form.submit();' } %> 

best of luck!


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -