I have a list of fields in a form that need to be validated against a database. I would prefer to have the validation occur every time the field loses focus (onblur event) rather than when the user does a submit. Does anyone know of an RoR example of how to do that? -- 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-/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 Jan 31, 2010, at 11:48 AM, Ralph Shnelvar wrote:> > I have a list of fields in a form that need to be validated against a > database. > > I would prefer to have the validation occur every time the field loses > focus (onblur event) rather than when the user does a submit. > > Does anyone know of an RoR example of how to do that?jQuery validate? http://docs.jquery.com/Plugins/Validation -- 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.
Ralph Shnelvar
2010-Jan-31 20:07 UTC
Re: jQuery, RoR, validating fields against a database
Steve Ross wrote:> jQuery validate? > > http://docs.jquery.com/Plugins/ValidationOh wow! ... Thanks!!!! -- 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-/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.
Marnen Laibow-Koser
2010-Jan-31 21:04 UTC
Re: jQuery, RoR, validating fields against a database
Ralph Shnelvar wrote:> I have a list of fields in a form that need to be validated against a > database. > > I would prefer to have the validation occur every time the field loses > focus (onblur event) rather than when the user does a submit. > > Does anyone know of an RoR example of how to do that?Remember not to rely on client-side validation. It''s very useful, but it''s easy to turn off JS and bypass it. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/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.
Ralph Shnelvar
2010-Jan-31 21:04 UTC
Re: jQuery, RoR, validating fields against a database
Steve Ross wrote:> On Jan 31, 2010, at 11:48 AM, Ralph Shnelvar wrote: >> >> I have a list of fields in a form that need to be validated against a >> database. >> >> I would prefer to have the validation occur every time the field loses >> focus (onblur event) rather than when the user does a submit. >> >> Does anyone know of an RoR example of how to do that? > > > jQuery validate? > > http://docs.jquery.com/Plugins/ValidationI think the jQuery validate function I want is "remote". Is there any way for that function to call a RoR action in a model or controller rather than more php or javascript? -- 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-/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.
Marnen Laibow-Koser
2010-Jan-31 21:06 UTC
Re: jQuery, RoR, validating fields against a database
Ralph Shnelvar wrote:> Steve Ross wrote: >> On Jan 31, 2010, at 11:48 AM, Ralph Shnelvar wrote: >>> >>> I have a list of fields in a form that need to be validated against a >>> database. >>> >>> I would prefer to have the validation occur every time the field loses >>> focus (onblur event) rather than when the user does a submit. >>> >>> Does anyone know of an RoR example of how to do that? >> >> >> jQuery validate? >> >> http://docs.jquery.com/Plugins/Validation > > I think the jQuery validate function I want is "remote". > > Is there any way for that function to call a RoR action in a model or > controller rather than more php or javascript?If you can call PHP, you can call Rails. The client-side JS knows nothing about the server-side scripting language. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/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.
steve ross
2010-Jan-31 21:40 UTC
Re: Re: jQuery, RoR, validating fields against a database
On Jan 31, 2010, at 1:04 PM, Ralph Shnelvar wrote:> > Steve Ross wrote: >> On Jan 31, 2010, at 11:48 AM, Ralph Shnelvar wrote: >>> >>> I have a list of fields in a form that need to be validated against a >>> database. >>> >>> I would prefer to have the validation occur every time the field loses >>> focus (onblur event) rather than when the user does a submit. >>> >>> Does anyone know of an RoR example of how to do that? >> >> >> jQuery validate? >> >> http://docs.jquery.com/Plugins/Validation > > I think the jQuery validate function I want is "remote". > > Is there any way for that function to call a RoR action in a model or > controller rather than more php or javascript?It''s easy. I don''t have any code close at hand, but it''s pretty straightforward -- stick the validation URL in an attribute you can access then use that. Just remember to have your authenticity certificate as part of the post data so Rails doesn''t suspect a forgery. Marnen''s right, you shouldn''t rely completely on client-side validation, but I typically do as much validation as possible on the client to avoid beating up the server and/or spoiling the client experience, then validate everything completely on the server to prevent attacks or mis-entries on the part of people who have disabled js. -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
steve ross
2010-Jan-31 22:01 UTC
Re: Re: jQuery, RoR, validating fields against a database
On Jan 31, 2010, at 1:04 PM, Ralph Shnelvar wrote:> > Steve Ross wrote: >> On Jan 31, 2010, at 11:48 AM, Ralph Shnelvar wrote: >>> >>> I have a list of fields in a form that need to be validated against a >>> database. >>> >>> I would prefer to have the validation occur every time the field loses >>> focus (onblur event) rather than when the user does a submit. >>> >>> Does anyone know of an RoR example of how to do that? >> >> >> jQuery validate? >> >> http://docs.jquery.com/Plugins/Validation > > I think the jQuery validate function I want is "remote". > > Is there any way for that function to call a RoR action in a model or > controller rather than more php or javascript?Here''s some old code I pulled off the shelf...uses jq validate var validator = $("#new_user").validate({ rules: { "user[login]": { required: true, minlength: 3, remote: "/users/login_taken" } } }); Pardon the abysmal formatting. -- 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.