Dave Methvin schrieb:
>
>> 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.
Dave, wait a moment, I understand all this and you are describing the
way it is in 1.04 and below.
But in jQuery 1.1. it is not like that and submit() invokes the submit
method of the form as well (at least according to the changelog). I was
trying to describe the concerns I have with that.
Again, from the changelog:
"* Performming .click(), .blur(), .focus(), .submit() will actually
trigger the browsers default action for those events."
And by the way: one cannot trigger the default click() action for links,
so I think, that one is useless. Also it seems that reset() is missing.
-- Klaus
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/