In Rails, I have a form on my Dish page that has a multi-select Chosen field called Side Dishes.
I'd like to have my Side Dishes Chosen field's options to automatically update (without page reload) if the user added another Side Dish from another browser window.
I looked into the Updating Chosen Dynamically from the Chosen website but I don't know if that's what I'm looking for and/or whether I'm understanding it correctly.
Currently, my dishes.js.coffee
looks like this:
jQuery ->
$(".chzn-side-dish").chosen()
$(".chzn-side-dish").trigger "liszt:updated"
But clearly that doesn't do the trick. My understanding was that the .trigger
will periodically refresh the Side Dish list and pick up on any new additions (or deletions) from the Side Dish table.
And the form on the Dish page follows this convention:
= form_for @dish, :html => { :class => "form-horizontal" } do |f|
...
%fieldset
.control-group
=f.label :side_dish_ids, "Side Dish(es)", :class => 'control-label'
.controls
=f.collection_select :side_dish_ids, SideDish.order(:name), :id, :name, {}, {multiple: true, :class => 'chzn-side-dish'}
PS -- I've looked at other SO questions but couldn't get it all to work. Again, I'm not sure whether I'm understanding the purpose of the .trigger...
properly.