Rails - Pass multiple checkbox values through params -


i using smart listing gem real time filtering. following simple form without submit , url.

<%= smart_listing_controls_for(:search) %>   <%= simple_form_for :search |f| %>     <%= f.input :certificates, collection: certificate.all, :as => :check_boxes, include_hidden: false, :input_html => {:multiple => true} %>   <% end> <% end> 

the above code generates multiple check-boxes 'certificate id's values. 1 of check-boxes checked, smart listing sends request controller params.

parameters: {"utf8"=>"✓", "search_smart_listing"=>{"_"=>"1", "page"=>"", "per_page"=>"10"}, "authenticity_token"=>"z25rulu5jeewcezdpsy0+bz7ojfdwpmxrvgnzpvdg0cjm0ufpc3ydb9+5gywdqkumcm6rgjnf0c4yrd0swpj6g==", "search"=>{ "certificates"=>["6"]}} 

the problem when select multiple check-boxes, certificates array has latest value , not selected check-boxes values.

also, when check-box selected , de-selected, certificates array value in params remains same. want value removed certificates array in params if check-box deselected , want certificates array have selected check-boxes values.

the following html code generated 1 of multiple check-boxes.

<span class="checkbox">   <label for="search_certificates_5">     <input class="check_boxes required" type="checkbox" value="5" name="search[certificates][]" id="search_certificates_5">      certificate 1   </label> </span> 

thanks in advance :)

since both smart_listing_controls_for , simple_form_for create form, 1 problem might have creating form inside form, , nor recommended nor standard. might lead unexpected results.

maybe try doing without simple_form helper, (assuming certificate has description attribute):

<%= smart_listing_controls_for(:search) %>   <%= certificate.all.each |certificate| %>     <div class="checkbox">       <label class= "checkbox inline">         <%= check_box_tag 'search[certificates][]', certificate.id %>         <%= certificate.description %>       </label>     </div>   <% end %> <% end %> 

update

also, there's problem current release (v1.1.2) of smart listing gem doesn't allow work array inputs. problem in part of javascript code. fixed on current master branch , updated on latest commit can see here.

to solve use latest commit in gemfile this:

gem 'smart_listing', :git => 'https://github.com/sology/smart_listing.git', :ref => '79adeba' 

bundle install after updating gemfile , try above code again.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -