1

I need a two sided multi select box in Rails (3.2.8), just like here:

http://www.stevefenton.co.uk/Content/Jquery-Two-Sided-Multi-Selector/

However, I can't get this to work with Rails and it is so poorly documented I have to give up on that one. (It shows but the buttons don't work, even on a fresh Rails app)

Does anyone know of a similar jquery or gem solution that DOES work with rails??

Many thanks!

bobomoreno
  • 2,848
  • 5
  • 23
  • 42
  • This isn't the answer you're looking for, but I'd urge you to reconsider why you want to do this in the first place. I've always found such interfaces to be needlessly complicated and can be confusing to some. Is there a reason you can't use a simple multi-select or check boxes? – Zach Kemp Nov 02 '12 at 22:10

1 Answers1

4

You could try this one: http://quasipartikel.at/multiselect/

Or this is another: http://loudev.com/

And then create your select something like the following in your Rails view (the "multiple" part is important for either plugin):

<%= f.select(:country, "country_id", Country.all.collect {|c| [ c.name, c.id ] }, {:include_blank => false}, {:class => "multiselect", :multiple => "multiple"}) %>

And also have the following JavaScript in your view:

<script>
$(document).ready(function (){
     $(".multiselect").multiselect();  // If you're using the quasipartikel one
     $('.multiselect').multiSelect();  // If you're using the loudev.com one
});
</script>
mccannf
  • 16,619
  • 3
  • 51
  • 63
  • Thanks, the one at loudev.com works well; realised I need to use 'serialize' to store the array correctly; One thing though, removing doesn't work (nothing happens when clicking values in the right column) I'm wondering if this is something to do with Rails' adding an empty "" to start of the selections?? Nearly there!! (Oddly AfterDeselect doesn't trigger with an alert on it, AfterSelect does... ??). No errors on java console – bobomoreno Nov 03 '12 at 10:16
  • Edited to remove the blank - may help you. (:include_blank => false) – mccannf Nov 03 '12 at 11:39
  • Already had that... :-) have a look here; I'm sure I'm missing something obvious; I've set it up as a barebones rails app https://github.com/dongennl/multiselect_rails Thanks!! – bobomoreno Nov 03 '12 at 11:54
  • 1
    Not sure where you got your `jquery.multi-select.js` file from. It has a typo (selectableLi instead of selectedLi on lines 214 and 218). This will have to be fixed in the JS. – mccannf Nov 03 '12 at 14:08
  • Thanks, I reported the same on their github and it is fixed now. All good!! Thanks for your help. – bobomoreno Nov 03 '12 at 14:39