Stan McFarland
2006-Feb-16 22:36 UTC
[Rails] newbie question regarding basic AJAX form verification
Hi, I''m confused about how form verification with AJAX works. Let''s say I have a ''new.rhtml'' view that contains a form with two fields, and the form action is ''create''. Let''s assume that I also want to do some type of data validation on one of the two fields via AJAX before I submit the form. But since I''ve already defined my form action with form_tag() as ''create'', I can''t also use form_remote_tag() at the same time, right? I''m sure I''m missing somethign obvious. but I could use some help. Thanks, Stan Mcfarland
Thomas
2006-Feb-17 09:30 UTC
[Rails] Re: newbie question regarding basic AJAX form verification
You could do your data validation directly in the method "create" of your controller. If data are wrong, just redisplay your form with a message error ... Thomas. -- Posted via http://www.ruby-forum.com/.
Stan McFarland
2006-Feb-17 13:47 UTC
[Rails] Re: newbie question regarding basic AJAX form verification
Thomas <thomas_mahier@...> writes:> > You could do your data validation directly in the method "create" of > your controller. If data are wrong, just redisplay your form with a > message error ... > > Thomas. >Yeah, but that''s not what I need to do. Think, for example, how a spell check application would work. You have one button to submit the form, and another button (or link) that does a spell check on a single textarea. This is what I can''t figure out how to do. -stan
BigSmoke
2006-Apr-04 13:05 UTC
[Rails] Re: newbie question regarding basic AJAX form verification
On 2/17/06, Stan McFarland <sfmcfar@gmail.com> wrote:> > Thomas <thomas_mahier@...> writes: > > > > > You could do your data validation directly in the method "create" of > > your controller. If data are wrong, just redisplay your form with a > > message error ... > > > > Thomas. > > > > Yeah, but that''s not what I need to do. Think, for example, how a spell > check > application would work. You have one button to submit the form, and > another > button (or link) that does a spell check on a single textarea. This is > what I > can''t figure out how to do. > > -stan >You can give the spell-check submit button a name, which you can then test for in @params within your action. - Rowan -- Morality is usually taught by the immoral. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060404/882b2058/attachment.html
Alan Francis
2006-Apr-04 15:32 UTC
[Rails] Re: newbie question regarding basic AJAX form verification
Hi Stan, I''d have a look at observe_field. http://www.railsmanual.org/module/ActionView::Helpers::PrototypeHelper/observe_field There is, as I''m often fond of pointing out, some stuff in Chad Fowler''s Rails Recipes on this. The example is the on-the-fly search (a la Google Suggest), but you can use observe_field to pass the contents of an individual field to an action periodically (say once a second) and return, say, some RJS to highlight the field red if it doesn''t validate. observe_field obviously only works with one field at a time, so I''m not sure how you''d pass the whole form periodically. <fx: googles around /> Oh wait, observe_form...of course it would be called observe_form :-) http://www.railsmanual.org/module/ActionView::Helpers::PrototypeHelper/observe_form Alan -- Posted via http://www.ruby-forum.com/.