views:

125

answers:

2

Hi,

i'm using the JQUERY multiselectable plugin. Because it's get one select box and transform it in two, where you can move one selected option to another select box. The problem is that i'm facing some problems with the edit action. When i load the form, the selected values (that are saved in my model) are not being populated in the "selected" select box. There is anybody with a good idea about how to "automatically" move the selected values in my database from the "available to be selected" to "selected" options?

For now i'm doing something like

<%= select "product", :option_ids, options_for_select(Option.all.map { |opt| [opt.description, opt.id]}), {},{:multiple=> true,:class=>'multiselect'} %>

Here i can see already the problem. I could just use as options_for_select just all options - the options that are already choosed in my model. The problem is how to update the select box with this information?

A: 

Try following

    <%= select "product", :option_ids, 
      options_for_select(Option.all.map { |opt| [opt.description, opt.id]} , [1,2, 3]),
 {},{:multiple=> true,:class=>'multiselect'} %>

Give one more Array parameter into the "options_for_select"

Hope that helps :)

Salil
super but it didn't work.
VP
it works for me dear. what problem u r facing?
Salil
you should put the value of Option you want o select instead of [1,2,3]
Salil
A: 

Because the jquery multiselectable plugin works hiding your select and show two news, with the content of your original select in the selectable "from" (you have a select "from" and a select "to") I just managed via jquery to add the information that i wanted in the select box "to". Until now looks like working.

VP