Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

@avioing
Copy link

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
Copy link
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.

@avioing
Copy link
Author

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
Copy link
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.

@avioing
Copy link
Author

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
Copy link
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.

@JangoSteve
Copy link
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?

@avioing
Copy link
Author

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
Copy link
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.

@avioing
Copy link
Author

avioing commented Mar 10, 2011

ok, done. the new issue id is 122

@mislav
Copy link
Member

mislav commented Mar 12, 2011

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

@neerajsingh0101
Copy link

pulled in d2abd6f

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

No branches or pull requests

4 participants