Wait, the whole point of this thread was that it works differently now. 

Yes, the form.submit() function now fires when you call $().submit().

No, there isn't a way to turn it off.

Yes, that doesn't seem to make much sense because it will submit your form,
then call the validation function and ignore the result. 

Yes, I would call that a bug. 

The offending code is in event.js:

if ( element[ type ] && element[ type ].constructor == Function )
        element[ type ](); 


-----Original Message-----
From: Dave Methvin [mailto:[EMAIL PROTECTED] 
Sent: Monday, January 08, 2007 8:47 AM
To: 'jQuery Discussion.'
Subject: RE: [jQuery] jQuery 1.1a (form submit)

 
>  The problem - that has also been discussed several times on the list 
> - with that feature is the following (I assume/hope it has been solved 
> therefore):
>
> // initialisation
> $('#my-form').submit(function() {
>     validate(this); // returns true or false });

So far so good, that sets the event handler. Although I must say, a new
jQuery user might think this submits the form immediately using the supplied
function as a validator. But it doesn't.

> // somewhere else
> $('#my-form').submit();

That calls the event handler. Calling the event handler does not submit the
form. Calling the form's submit() method like $("#my-form")[0].submit()
would submit the form, but it would not necessarily call the handler per the
W3C spec: 

http://www.w3.org/TR/DOM-Level-2-HTML/html.html
"Note: The onsubmit even handler is not guaranteed to be triggered when
invoking this method. The behavior is inconsistent for historical reasons
and authors should not rely on a particular one."

So your code should look like this:

  if ( validate($("my-form")[0]) )
    $("my-form")[0].submit();

I think jQuery's .submit() method should be removed because of just this
type of confusion. Since you are already running code it is just as easy to
call the validation function explicitly rather than depending on the
onsubmit event.




_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to