I have the following code that I''m using to validate the form:
Event.observe(''form'', ''submit'',
function () {
return (
check_first_name() && check_last_name() &&
check_username() && check_password() && check_password_confirm()
);
});
How do stop the form from submitting if I return false?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
Matt Alexander wrote:> I have the following code that I''m using to validate the form: > > Event.observe(''form'', ''submit'', function () { > return ( > check_first_name() && check_last_name() && > check_username() && check_password() && check_password_confirm() > ); > }); > > How do stop the form from submitting if I return false? >When attaching events via the DOM instead of inline, you need to stop events from propagating. Try Event.stop(): Event.observe(''form'', ''submit'', function (evt) { if ( !(check_first_name() && check_last_name() && check_username() && check_password() && check_password_confirm()) { Event.stop(evt); } }.bindAsEventListener() }); --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Matt Alexander
2007-Feb-07 22:03 UTC
Re: How do I return false so that a form won''t submit?
That was perfect, thanks! On Feb 7, 2:50 pm, Ken Snyder <ksny...-evSXmdsRj0TQT0dZR+AlfA@public.gmane.org> wrote:> Matt Alexander wrote: > > I have the following code that I''m using to validate the form: > > > Event.observe(''form'', ''submit'', function () { > > return ( > > check_first_name() && check_last_name() && > > check_username() && check_password() && check_password_confirm() > > ); > > }); > > > How do stop the form from submitting if I return false? > > When attaching events via the DOM instead of inline, you need to stop > events from propagating. Try Event.stop(): > > Event.observe(''form'', ''submit'', function (evt) { > if ( !(check_first_name() && > check_last_name() && > check_username() && > check_password() && > check_password_confirm()) { > Event.stop(evt); > } > }.bindAsEventListener() > > });--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Try it this way:
Event.observe(''form'', ''submit'', function
(evt) { // Added function param
Event.stop(evt); // Stop propogation;
return (
check_first_name() && check_last_name() &&
check_username() && check_password() && check_password_confirm()
);
});
Returning false only works if the function is directly set as the
event handler, rather than being attached/observed (i.e. $
(''form'').onsubmit = function() {return false;}, although using
Event.stop() is not in appropriate in this instance, although you''d
also need to bindAsEventListener() or implement some other cross-
browser method of getting the event.
I hope my ramblings make sense.
TAG
tomg-PGZyUNKar/Q@public.gmane.org
On Feb 7, 2007, at 2:39 PM, Matt Alexander wrote:
>
> I have the following code that I''m using to validate the form:
>
> Event.observe(''form'',
''submit'', function () {
> return (
> check_first_name() && check_last_name() &&
> check_username() && check_password() &&
check_password_confirm()
> );
> });
>
> How do stop the form from submitting if I return false?
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---