Forum: Ruby on Rails newbie question regarding basic AJAX form verification

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Stan McFarland (Guest)
on 2006-02-17 00:38
(Received via mailing list)
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 (Guest)
on 2006-02-17 11:30
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.
Stan McFarland (Guest)
on 2006-02-17 15:49
(Received via mailing list)
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 (Guest)
on 2006-04-04 17:08
(Received via mailing list)
On 2/17/06, Stan McFarland <removed_email_address@domain.invalid> wrote:
>
> 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
Alan F. (Guest)
on 2006-04-04 19:32
Hi Stan,

I'd have a look at observe_field.

http://www.railsmanual.org/module/ActionView::Help...

There is, as I'm often fond of pointing out, some stuff in Chad F.'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::Help...

Alan
This topic is locked and can not be replied to.