Hi I am using something like the following code to show an array of checkboxes within a form <% @froglets.each do |froglet| -%> <%= check_box_tag "note[froglet_ids][]", froglet.id %> <%= h froglet.name %><br /> <% end %> These get submitted as an array and all works well, except for the fact that firebug gives me warnings on the page (anchor note_froglet_ids_ is already defined) as all the checkboxes have the same name attribute. Is there an alternative method of achieving display and submit of an array of checkboxes that generates fully valid html? Using rails 2.3.2. I can update rails if it will help. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> > <%= check_box_tag "note[froglet_ids][]", froglet.id %> <%= h > froglet.name %><br /> > > These get submitted as an array and all works well, except for the > fact that firebug gives me warnings on the page (anchor > note_froglet_ids_ is already defined) as all the checkboxes have the > same name attribute. >How about using something like: <%= check_box_tag "note[froget_ids][]", froglet.id, :id => "note_froglet_id_#{froglet.id}" %> The ID is automatically generated from the name, given that they''re all having the same name it''s not surprising they''re all having the same ID. Cheers, Andy -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 8 March 2010 08:55, Andy Jeffries <andyjeffries-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:>> <%= check_box_tag "note[froglet_ids][]", froglet.id %> <%= h >> froglet.name %><br /> >> >> These get submitted as an array and all works well, except for the >> fact that firebug gives me warnings on the page (anchor >> note_froglet_ids_ is already defined) as all the checkboxes have the >> same name attribute. > > How about using something like: > <%= check_box_tag "note[froget_ids][]", froglet.id, :id => > "note_froglet_id_#{froglet.id}" %> > The ID is automatically generated from the name, given that they''re all > having the same name it''s not surprising they''re all having the same ID.Rather to my surprise this has removed the warnings (it is the html validator plugin for FF that is showing the warnings of course, not firebug). I am surprised as I thought that the name and id both have to be unique and while this fixes the id the names are still the same. In fact the error in the validator specifically referred to the name. Having fed the source into the w3c validator however it specifically complains about the ids not being unique, and treats it as an error not a warning, so this may be a deficiency in the validator plugin. Many thanks for the help. Colin> Cheers, > > Andy > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> > Rather to my surprise this has removed the warnings (it is the html > validator plugin for FF that is showing the warnings of course, not > firebug).Always glad to surprise you.> I am surprised as I thought that the name and id both have > to be unique and while this fixes the id the names are still the same. >This is absolutely correct and valid (and the fact that the ids are added to an array is something that PHP coders have relied on for at least 10 years - I know I was one of them).> In fact the error in the validator specifically referred to the name. > Having fed the source into the w3c validator however it specifically > complains about the ids not being unique, and treats it as an error > not a warning, so this may be a deficiency in the validator plugin. >I think it must be, there''s no requirement for names to be unique. Cheers, Andy -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.