live("submit") and .submit() would cause unobtrusive ajax live to fire twice
|Reported by:||Owned by:||dmethvin|
I have code using jquery 1.7, MVC 3 unobtrusive ajax, jquery ui 1.8.5, and some custom dialog code. In my dialog code I convert a non-ajax form to an ajax form via adding the appropriate attributes for unobtrusive ajax to work with the form. in the button events for the dialog I call form.submit().
On the first load of the page the unobtrusive ajax live("submit") bidning would fire twice causing my form to be submitted twice.
I traced this issue to some code added (i presume in 1.7 sicne this issue started recently) for handling IE submit delegation. (lines 3605 - 3631 if the main js)
This code attaches a submit._submit handler which will fire a simulated submit. The problem seems to be that when I call .submit() the live handler is fired, then this simulate is fired, which in turn fires the live handler again.
I can work around the issue by removing the submit._submit event before i call .submit() which then prevents the simulated submit from firing.
example: jQuery.event.remove(form, "submit._submit"); form.submit();
without the above code the live submtis twice, with the above it only submits once. This works for me because this form will only be submitted via code, but this may not be a practical work around for other uses. I think the issue is with the .submit() call, maybe it should have a wrapper that will disable the extra event since it is envoked manually anyway.
Change History (6)
comment:1 Changed 5 years ago by
|Component:||unfiled → event|
|Milestone:||None → 1.7.1|
|Owner:||set to dmethvin|
|Priority:||undecided → blocker|
|Status:||new → assigned|