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

Already on GitHub? Sign in to your account

Fix for ValidationEngine & hiding errors on change. #374

Merged
merged 1 commit into from Sep 5, 2012

Conversation

Projects
None yet
3 participants

tzarger commented Sep 4, 2012

Copying class attribute to container causes and issue with the JQuery ValidationEngine. In order to prevent double validation, a simple regex replace call to copy all but the actual validation[] class.

Also, added a blurOnChange default setting, to allow people to trigger and blur() event in case of using JQuery ValidationEngine in order to immediately hide the validation error message when selecting an option.

Fix for ValidationEngine &hiding errors on change.
Copying class attribute to container causes and issue with the JQuery
ValidationEngine. In order to prevent double validation checking, a
simple replace call to copy all but the actual validation[] class.

Also, added a blurOnChange default setting, to allow people to trigger
and blur() event in case of using JQuery ValidationEngine  in order to
immediately hide the validation error message when selecting an option.

seems strange to fire a blur from change. why not fire change? or fire blur when the component is actually blurred....

Owner

tzarger replied Sep 5, 2012

This is a specific fix for Jquery ValidationEngine. It attaches a blur event for text, select, etc. So therefor a change event is never heard.

If you never fire the blur event, the validation message does not disappear until you click to submit the form. If all the other validation messages disappear on blur events of the text elements, it seems strange like the select in the select2 drop down did not take as it is the last and only (if one on the form) validation message that never goes away. So you may think you need to do something else to make that disappear and may not be obvious to hit the submit button.

that is the reason I added a configuration option (blurOnChange) as it is not a normal solution, however you would need to emit that event in order to have Jquery ValidationEngine work as the same behavior as all other validation.

Keep in mind, you fire a blur event on the actual element and thus nothing visually blurs.

I agree, it seems a bit strange. Without going into the plumbing with validationEngine, this is an easy fix (not really a fix, just an enhancement to expand compatibility), Granted I have a pull request to updating prompt position on the select2 element when the screen is resized. It could be made to like to a change event if you feel it is better to request an update there. Please let me know your thoughts.

ivaynberg added a commit that referenced this pull request Sep 5, 2012

Merge pull request #374 from tzarger/master
Fix for ValidationEngine & hiding errors on change.

@ivaynberg ivaynberg merged commit cb44a86 into select2:master Sep 5, 2012

DevXen commented Dec 20, 2012

I'm using the Jquery ValidationEngine. but can't figure out how to get it to validate if select2 has anything selected or not?

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