I have a form which contains widgEditor (http://www.themaninblue.com/ experiment/widgEditor/) elements. This script adds onsubmit calls to the form to clean itself up before submitting values. The problem arises when I try to submit the form through javascipt with $(form).submit();. When this happens it does not fire any of the onSubmit functions which widg added. This works fine if i submit the form through a normal submit button. This is the code in widg (I do not want to change this, just for reference). theForm.observe(''submit'', function(e) { How can I get my JS to execute the onsubmit actions? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
That is correct, submit observers are not called when you call form.submit(). If you need to be able to call form.submit() as well as trap the user submission mechanism, you need to factor out your code into something you can call from both places. -Fred On Tue, Jul 1, 2008 at 10:28 AM, louis w <louiswalch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I have a form which contains widgEditor (http://www.themaninblue.com/ > experiment/widgEditor/<http://www.themaninblue.com/experiment/widgEditor/>) > elements. This script adds onsubmit calls to > the form to clean itself up before submitting values. > > The problem arises when I try to submit the form through javascipt > with $(form).submit();. When this happens it does not fire any of the > onSubmit functions which widg added. This works fine if i submit the > form through a normal submit button.-- Science answers questions; philosophy questions answers. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks Fred. Do you know of a way to submit a form through js and have it honor the observers? I would prefer not to alter the 3rd party code. This could be problematic for future upgrades. On Jul 1, 11:31 am, "Frederick Polgardy" <f...-SMQUYeM9IBBWk0Htik3J/w@public.gmane.org> wrote:> That is correct, submit observers are not called when you call > form.submit(). If you need to be able to call form.submit() as well as trap > the user submission mechanism, you need to factor out your code into > something you can call from both places. > > -Fred > > On Tue, Jul 1, 2008 at 10:28 AM, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I have a form which contains widgEditor (http://www.themaninblue.com/ > > experiment/widgEditor/<http://www.themaninblue.com/experiment/widgEditor/>) > > elements. This script adds onsubmit calls to > > the form to clean itself up before submitting values. > > > The problem arises when I try to submit the form through javascipt > > with $(form).submit();. When this happens it does not fire any of the > > onSubmit functions which widg added. This works fine if i submit the > > form through a normal submit button. > > -- > Science answers questions; philosophy questions answers.--~--~---------~--~----~------------~-------~--~----~ 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 sending the form with $(''submit_button'').click() -- new-school meets old-school. Walter On Jul 1, 2008, at 11:28 AM, louis w wrote:> How can I get my JS to execute the onsubmit actions?--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I''d guess you could fire the event with the browser Event API (element.fire in Prototype tries to iron out the browser issues), but I''m not sure, I haven''t tried it. On Tue, Jul 1, 2008 at 10:39 AM, louis w <louiswalch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Thanks Fred. > Do you know of a way to submit a form through js and have it honor the > observers? > I would prefer not to alter the 3rd party code. This could be > problematic for future upgrades.-- Science answers questions; philosophy questions answers. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Nice one. .click() works. Thanks. On Jul 1, 11:41 am, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> Try sending the form with $(''submit_button'').click() -- new-school > meets old-school. > > Walter > > On Jul 1, 2008, at 11:28 AM, louis w wrote: > > > How can I get my JS to execute the onsubmit actions?--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Jul 1, 4:43 pm, "Frederick Polgardy" <f...-SMQUYeM9IBBWk0Htik3J/w@public.gmane.org> wrote:> I''d guess you could fire the event with the browser Event API (element.fire > in Prototype tries to iron out the browser issues), but I''m not sure, I > haven''t tried it. >No, Element#fire is specifically only for custom events, not native ones. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Tue, Jul 1, 2008 at 11:09 AM, louis w <louiswalch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Nice one. .click() works. Thanks.If you have an inline JavaScript handler for the submit event, then you can fire it by just calling onsubmit like a method. Given: <form onsubmit="doStuff()" id="my-form"> ... </form> $(''my-form'').onsubmit() Think of it as a named method just waiting to be invoked. -justin --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Right, you just can''t do this if you''ve registered it with observe(). -Fred On Jul 2, 2008, at 10:17 AM, Justin Perkins wrote:> > On Tue, Jul 1, 2008 at 11:09 AM, louis w <louiswalch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Nice one. .click() works. Thanks. > > If you have an inline JavaScript handler for the submit event, then > you can fire it by just calling onsubmit like a method. > > Given: > > <form onsubmit="doStuff()" id="my-form"> > ... > </form> > > > $(''my-form'').onsubmit() > > Think of it as a named method just waiting to be invoked. > > -justin-- Science answers questions; philosophy questions answers. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---