AmadeusRex
2008-Apr-09 00:03 UTC
how to replicate onsubmit="return func" with Form.EventObserver
hi, i wanted to replace the onsubmit="return func(this);" which PREVENTS form submission when validation fails with this: document.observe(''dom:loaded'', function() { $$("form.do_validate").each(function(ef){ new Form.EventObserver(ef,func(ef)); }); }); the problem is, the form STILL SUBMITS even when the validation fails using the above code. how do i replicate the onsubmit="return func(this);" using prototype? thanks --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Walter Lee Davis
2008-Apr-09 00:27 UTC
Re: how to replicate onsubmit="return func" with Form.EventObserver
If you want to observe a form''s submit method, and stop the default behavior, simply do this: $(''your_form_id'').observe(''submit'', function(evt){ evt.stop(); //do whatever else you like here now, the form won''t go any further }); Walter On Apr 8, 2008, at 8:03 PM, AmadeusRex wrote:> > hi, > > i wanted to replace the onsubmit="return func(this);" which PREVENTS > form submission when validation fails with this: > > document.observe(''dom:loaded'', function() { > $$("form.do_validate").each(function(ef){ > new Form.EventObserver(ef,func(ef)); > }); > }); > > the problem is, the form STILL SUBMITS even when the validation fails > using the above code. > > how do i replicate the onsubmit="return func(this);" using prototype? > > thanks > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
AmadeusRex
2008-Apr-09 00:55 UTC
Re: how to replicate onsubmit="return func" with Form.EventObserver
walter, thanks for the help! i modified my function and incorporated your suggestion to come up with: document.observe(''dom:loaded'', function() { $$("form.do_validate").each(function(ef){ ef.observe(''submit'', function(event){ if (!checkvalid(ef)) { event.stop(); } }); }); }); --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---