I have a collection of check_box_tags that look like the following: <% for item in @items %> <%= check_box_tag "item[item_ids][]", item.id, false, {:onchange => remote_function(:url => update_items_path, :with => "''items='' + escape(value) "} %> <%= item.name %> <% end %> My question is, how do I send all of the current checkbox values (item[item_ids][]) in the onchange? Currently, I am only getting the value of the changed checkbox (ie: items=2), but I need to know which other checkboxes are checked. Thanks, bucks --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Is there a reason not to manage ONLY the change, rather than trying to manage the entire collection on each change? Seems like it''d be more efficient to take the id/value that you receive and either to a x.items << Item.find(id) or x.items.delete Item.find(id). Regardless, it sounds like you''d want either an observe_form (sees all the changes and submits the entire form) or you could wrap up the check boxes in some container (fieldset, div, etc), give the container a name, and then use: remote_function(:url=>..., :submit=>''container_id'') That will serialize the values of all the input elements in the container. Note that you''ll only receive the ids of check boxes that are checked. On Mar 2, 4:56 pm, bucks <wla...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a collection of check_box_tags that look like the following: > > <% for item in @items %> > <%= check_box_tag "item[item_ids][]", item.id, false, {:onchange => > remote_function(:url => update_items_path, :with => "''items='' + > escape(value) "} %> > <%= item.name %> > <% end %> > > My question is, how do I send all of the current checkbox values > (item[item_ids][]) in the onchange? Currently, I am only getting the > value of the changed checkbox (ie: items=2), but I need to know which > other checkboxes are checked. > > Thanks, > bucks--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for the response. Definitely some good options. I think I will give the :submit => ''container_id'' a shot, as it seems most inline with what i''m trying to do. Cheers, On Mar 3, 10:59 am, AndyV <a...-HmMyXyqgL2CVc3sceRu5cw@public.gmane.org> wrote:> Is there a reason not to manage ONLY the change, rather than trying to > manage the entire collection on each change? Seems like it''d be more > efficient to take the id/value that you receive and either to a > x.items << Item.find(id) or x.items.delete Item.find(id). Regardless, > it sounds like you''d want either an observe_form (sees all the changes > and submits the entire form) or you could wrap up the check boxes in > some container (fieldset, div, etc), give the container a name, and > then use: > > remote_function(:url=>..., :submit=>''container_id'') > > That will serialize the values of all the input elements in the > container. Note that you''ll only receive the ids of check boxes that > are checked. > > On Mar 2, 4:56 pm, bucks <wla...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I have a collection of check_box_tags that look like the following: > > > <% for item in @items %> > > <%= check_box_tag "item[item_ids][]", item.id, false, {:onchange => > > remote_function(:url => update_items_path, :with => "''items='' + > > escape(value) "} %> > > <%= item.name %> > > <% end %> > > > My question is, how do I send all of the current checkbox values > > (item[item_ids][]) in the onchange? Currently, I am only getting the > > value of the changed checkbox (ie: items=2), but I need to know which > > other checkboxes are checked. > > > Thanks, > > bucks--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---