rails ujs driver + jquery-validation + ajax form - causes validation to be silently ignored (only IE) #118

Closed
avioing opened this Issue Mar 7, 2011 · 11 comments

Comments

Projects
None yet
4 participants
@avioing

avioing commented Mar 7, 2011

not clear to me whether the problem is with the ujs driver or jquery-validate...

when using jquery UJS driver (most recent) and an ajax form (via the data-remote tag), the validation rules are silently ignored. only in IE 8, chrome and FF work fine

tested with jquery 1.4.4 and jquery 1.5.1, using most recent jquery-validation from github.

here is a simple example:
http://avioing.com/validate/example.html and
http://avioing.com/validate/example_no_ujs.html
the only difference between the two files is that i removed "data-remote" tag from the form in the latter file, and now validation is triggered.

@JangoSteve

This comment has been minimized.

Show comment
Hide comment
@JangoSteve

JangoSteve Mar 10, 2011

Member

I glanced through the source code of the jquery-validation plugin (I assume you're referring to this one), and it appears this is not resolvable from the jquery-ujs end; it would require a change to the jquery-validation plugin.

We can see on this line of the validation plugin, it triggers the validation from the form's submit event. However, the entire purpose of jquery-ujs is to submit the form via ajax, which bypasses the standard form submission and page refresh.

The best solution all around, would be if Jörn (the author of the validation plugin) allowed the validation trigger to be configurable, so that the validation could be triggered from any event. Then you could trigger validation with jquery-ujs's ajax:beforeSend event.

I'd consider starting a ticket over there asking for this feature or pointing to this ticket.

Member

JangoSteve commented Mar 10, 2011

I glanced through the source code of the jquery-validation plugin (I assume you're referring to this one), and it appears this is not resolvable from the jquery-ujs end; it would require a change to the jquery-validation plugin.

We can see on this line of the validation plugin, it triggers the validation from the form's submit event. However, the entire purpose of jquery-ujs is to submit the form via ajax, which bypasses the standard form submission and page refresh.

The best solution all around, would be if Jörn (the author of the validation plugin) allowed the validation trigger to be configurable, so that the validation could be triggered from any event. Then you could trigger validation with jquery-ujs's ajax:beforeSend event.

I'd consider starting a ticket over there asking for this feature or pointing to this ticket.

@avioing

This comment has been minimized.

Show comment
Hide comment
@avioing

avioing Mar 10, 2011

thanks steve... i will pass this on. the interesting thing is that the code with ujs works in chrome and ff, but not ie. which is confusing since you are saying there is a fundamental issue with jquery-validate's dependency on the submit event

avioing commented Mar 10, 2011

thanks steve... i will pass this on. the interesting thing is that the code with ujs works in chrome and ff, but not ie. which is confusing since you are saying there is a fundamental issue with jquery-validate's dependency on the submit event

@JangoSteve

This comment has been minimized.

Show comment
Hide comment
@JangoSteve

JangoSteve Mar 10, 2011

Member

Oh interesting. I missed the part about this being an IE-only problem. I'm probably wrong then. In fact, now that I think about it, the form submit binding from the validation plugin should be triggered before it bubbles to the document node, where rails.js is triggered.

It sounds like this may be related to the IE submit bubbling issue that I mentioned on your other ticket. Any chance you can try this with the rails.js from this fork and see if that works?

EDIT: The reason this may work is because, it may be that the validation is canceling the event, but that jQuery is still manually triggering the form submission in IE, which is explained in that pull request. Just a guess though.

Member

JangoSteve commented Mar 10, 2011

Oh interesting. I missed the part about this being an IE-only problem. I'm probably wrong then. In fact, now that I think about it, the form submit binding from the validation plugin should be triggered before it bubbles to the document node, where rails.js is triggered.

It sounds like this may be related to the IE submit bubbling issue that I mentioned on your other ticket. Any chance you can try this with the rails.js from this fork and see if that works?

EDIT: The reason this may work is because, it may be that the validation is canceling the event, but that jQuery is still manually triggering the form submission in IE, which is explained in that pull request. Just a guess though.

@avioing

This comment has been minimized.

Show comment
Hide comment
@avioing

avioing Mar 10, 2011

steve, thanks. i tested your patched rails.js, and it did not work. here is the example - http://avioing.com/validate/example.iefix.html

the example is dead simple, it's a two field form, and the only include files are jquery, ujs and jquery-validate. feel free to play with it

cheers

avioing commented Mar 10, 2011

steve, thanks. i tested your patched rails.js, and it did not work. here is the example - http://avioing.com/validate/example.iefix.html

the example is dead simple, it's a two field form, and the only include files are jquery, ujs and jquery-validate. feel free to play with it

cheers

@JangoSteve

This comment has been minimized.

Show comment
Hide comment
@JangoSteve

JangoSteve Mar 10, 2011

Member

Wow, that's amazing. Talk about dumb luck :-) I'll leave a comment on the pull request pointing to this issue as well, so that they know to close it when it's merged.

Member

JangoSteve commented Mar 10, 2011

Wow, that's amazing. Talk about dumb luck :-) I'll leave a comment on the pull request pointing to this issue as well, so that they know to close it when it's merged.

@JangoSteve

This comment has been minimized.

Show comment
Hide comment
@JangoSteve

JangoSteve Mar 10, 2011

Member

Just realized this is already closed. Probably my fault for thinking it was a jquery-validation issue at first. Will it allow you to re-open it until it's resolved?

Member

JangoSteve commented Mar 10, 2011

Just realized this is already closed. Probably my fault for thinking it was a jquery-validation issue at first. Will it allow you to re-open it until it's resolved?

@avioing

This comment has been minimized.

Show comment
Hide comment
@avioing

avioing Mar 10, 2011

steve - sorry, i am totally confused :). just to be clear, your patched rails.js DID NOT work...

as to the ticket - unfortunately, i do not see a way to re-open it from my end. thanks

avioing commented Mar 10, 2011

steve - sorry, i am totally confused :). just to be clear, your patched rails.js DID NOT work...

as to the ticket - unfortunately, i do not see a way to re-open it from my end. thanks

@JangoSteve

This comment has been minimized.

Show comment
Hide comment
@JangoSteve

JangoSteve Mar 10, 2011

Member

Wow, I am just not reading your comments right for some reason :-P Sorry about that. I'd say open a new ticket then and maybe point it to this one in the description.

Member

JangoSteve commented Mar 10, 2011

Wow, I am just not reading your comments right for some reason :-P Sorry about that. I'd say open a new ticket then and maybe point it to this one in the description.

@avioing

This comment has been minimized.

Show comment
Hide comment
@avioing

avioing Mar 10, 2011

ok, done. the new issue id is 122

avioing commented Mar 10, 2011

ok, done. the new issue id is 122

@mislav

This comment has been minimized.

Show comment
Hide comment
@mislav

mislav Mar 12, 2011

Member

Someone (me?) closed this accidentally. JangoSteve generously provided a fix in pull req #123

Member

mislav commented Mar 12, 2011

Someone (me?) closed this accidentally. JangoSteve generously provided a fix in pull req #123

@neerajdotname

This comment has been minimized.

Show comment
Hide comment
Member

neerajdotname commented Apr 15, 2011

pulled in d2abd6f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment