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?
on 2008-07-01 17:29
on 2008-07-01 17:32
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@gmail.com> 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.
on 2008-07-01 17:39
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 2008-07-01 17:42
Try sending the form with $('submit_button').click() -- new-school
meets old-school.
Walter
on 2008-07-01 17:43
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@gmail.com> 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.
on 2008-07-02 10:52
On Jul 1, 4:43 pm, "Frederick Polgardy" <f...@polgardy.com> 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.
on 2008-07-02 17:18
On Tue, Jul 1, 2008 at 11:09 AM, louis w <louiswalch@gmail.com> 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
on 2008-07-02 17:21
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: > ... > </form> > > > $('my-form').onsubmit() > > Think of it as a named method just waiting to be invoked. > > -justin -- Science answers questions; philosophy questions answers.