Hi, The default way we handle an array of checkboxes is like this: <% items.each do |item| %> <%= check_box_tag ''item[]'', "#{item.id}" %> <% end -%> this returns an array item[] that holds the ids of all the items. Now the real issue: 1. The above loop will same ids to ''n'' items 2. All ids will be ''item[]'' Both of the above points are not XHTML Strict 1.0 valid and hence I am seeking a solution. An alternative could be like I assign each check box a unique id like this: <% items.each do |item| %> <%= check_box_tag "item_#{item.id}", "#{item.id}" %> <% end -%> But this will involve an overhead of collecting all ids in controller. Any new ideas ?? ~rd -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Jan 31, 2008 7:35 AM, Saz Wqa <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> The default way we handle an array of checkboxes is like this: > > <% items.each do |item| %> > <%= check_box_tag ''item[]'', "#{item.id}" %> > <% end -%> > > this returns an array item[] that holds the ids of all the items. > > Now the real issue: > > 1. The above loop will same ids to ''n'' items > 2. All ids will be ''item[]'' > > Both of the above points are not XHTML Strict 1.0 valid and hence I am > seeking a solution.gsub to replace the square brackets with something else?> An alternative could be like I assign each check box a unique id like > this: > > <% items.each do |item| %> > <%= check_box_tag "item_#{item.id}", "#{item.id}" %> > <% end -%> > > But this will involve an overhead of collecting all ids in controller.You first example shows using item.id, so how is not also an overhead there? If you need the ids then you need the ids, overhead or not. -- Greg Donald http://destiney.com/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Rimantas Liubertas
2008-Feb-01 21:56 UTC
Re: Handling multiple Check boxes in a XHTML Strict way
> The default way we handle an array of checkboxes is like this: > > <% items.each do |item| %> > <%= check_box_tag ''item[]'', "#{item.id}" %> > <% end -%> > > this returns an array item[] that holds the ids of all the items. > > Now the real issue: > > 1. The above loop will same ids to ''n'' items > 2. All ids will be ''item[]'' > > Both of the above points are not XHTML Strict 1.0 valid and hence I am > seeking a solution. > > An alternative could be like I assign each check box a unique id like > this: > > <% items.each do |item| %> > <%= check_box_tag "item_#{item.id}", "#{item.id}" %> > <% end -%> > > But this will involve an overhead of collecting all ids in controller. > > Any new ideas ??Yes. Use the same name attribute with [] and different ids: <% 5.times do |i| %> <%= check_box_tag "cb_[#{i}]", value="#{i}", false, :id => "cb_#{i}" %> <% end %> Regards, Rimantas -- http://rimantas.com/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Rishav Dixit
2008-Feb-05 10:46 UTC
Re: Handling multiple Check boxes in a XHTML Strict way
Thanks a lot ! I got it solved. So stupid of me to not note this fact that rails works by collecting ''name'' attribute and not ''id''. regards, ~rd Rimantas Liubertas wrote:>> 1. The above loop will same ids to ''n'' items >> <% end -%> >> >> But this will involve an overhead of collecting all ids in controller. >> >> Any new ideas ?? > > Yes. Use the same name attribute with [] and different ids: > > <% 5.times do |i| %> > <%= check_box_tag "cb_[#{i}]", value="#{i}", false, :id => "cb_#{i}" %> > <% end %> > > > Regards, > Rimantas > -- > http://rimantas.com/-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---