Andreas Hallberg
2007-Jul-03 21:18 UTC
"form_for" names fields using brackets = javascript problems
Hi all, The "form_for" helper and its friends "text_field_for" etc generate form fields with names like "forum[title]", i.e. using square brackets to denote attributes on model objects. Now, for the convenience of the user I want to do some simple client-side validation to check that some fields have been filled in. So I am trying to write javascript like "if (myForm.forum[title].value == '''') { return false; }", but ofcourse the "title" in the brackets is interpreted as the name of a child object of a "forum" object in the DOM for the page. Doh! Is there a way to solve this? I realize this is more a javascript question than RoR question, but I have looked fruitlessly for an answer and I figure people trying client-side validation in RoR must have stumbled on this problem. Please note that I am NOT using client-side validation to replace server-side, it is just used as an added benefit for javascript enabled clients. Thanks, /Andreas -- 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 -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom
2007-Jul-04 01:02 UTC
Re: "form_for" names fields using brackets = javascript problems
> The "form_for" helper and its friends "text_field_for" etc generate form > fields with names like "forum[title]", i.e. using square brackets to > denote attributes on model objects. > > Now, for the convenience of the user I want to do some simple > client-side validation to check that some fields have been filled in. So > I am trying to write javascript like > > "if (myForm.forum[title].value == '''') { return false; }",myForm.elements[''forum[title]''].value -philip> > but ofcourse the "title" in the brackets is interpreted as the name of > a child object of a "forum" object in the DOM for the page. Doh! > > Is there a way to solve this? > > I realize this is more a javascript question than RoR question, but I > have looked fruitlessly for an answer and I figure people trying > client-side validation in RoR must have stumbled on this problem. > > Please note that I am NOT using client-side validation to replace > server-side, it is just used as an added benefit for javascript enabled > clients. > > Thanks, > > /Andreas > > -- > 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 -~----------~----~----~----~------~----~------~--~---
Andreas Hallberg
2007-Jul-04 05:58 UTC
Re: "form_for" names fields using brackets = javascript prob
Philip Hallstrom wrote:>> The "form_for" helper and its friends "text_field_for" etc generate form >> fields with names like "forum[title]", i.e. using square brackets to >> denote attributes on model objects. >> >> Now, for the convenience of the user I want to do some simple >> client-side validation to check that some fields have been filled in. So >> I am trying to write javascript like >> >> "if (myForm.forum[title].value == '''') { return false; }", > > myForm.elements[''forum[title]''].value > > -philipThanks philip! I''ll try it out later today, seems like it will get the job done! /Andreas -- 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 -~----------~----~----~----~------~----~------~--~---