Skip to content

Fix extend bug may be pollute global variable $.formUtils.LANG #90

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

Merged
merged 2 commits into from
Feb 2, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions form-validator/jquery.form-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,26 @@
return this;
};

/*
* Assigns validateInputOnBlur function to elements custom event
* @param {Object} language Optional, will override $.formUtils.LANG
* @param {Object} settings Optional, will override the default settings
* * @return {jQuery}
*/
$.fn.validateOnEvent = function(language, settings) {
this.find('input[data-validation][data-validation-event],textarea[data-validation][data-validation-event]')
.each(function(){
var $el = $(this),
etype = $el.attr("data-validation-event");
if (etype){
$el.bind(etype + ".validation", function(){
$(this).validateInputOnBlur(language, settings, false, etype);
});
}
});
return this;
};

/**
* fade in help message when input gains focus
* fade out when input loses focus
Expand Down Expand Up @@ -145,7 +165,7 @@
if(!eventContext)
eventContext = 'blur';

language = $.extend($.formUtils.LANG, language || {});
language = $.extend({}, $.formUtils.LANG, language || {});
_removeErrorStyle(this, conf);

var $elem = this,
Expand Down Expand Up @@ -209,7 +229,7 @@
*/
$.fn.validateForm = function(language, conf) {

language = $.extend($.formUtils.LANG, language || {});
language = $.extend({}, $.formUtils.LANG, language || {});

$.formUtils.isValidatingEntireForm = true;
$.formUtils.haltValidation = false;
Expand Down Expand Up @@ -399,6 +419,10 @@

var defaultConf = $.extend($.formUtils.defaultConfig(), {
form : 'form',
/*
* Enable custom event for validation
*/
validateOnEvent : true,
validateOnBlur : true,
showHelpOnFocus : true,
addSuggestions : true,
Expand Down Expand Up @@ -464,6 +488,10 @@
if( conf.validateOnBlur ) {
$form.validateOnBlur(conf.language, conf);
}
if( conf.validateOnEvent ){
$form.validateOnEvent(conf.language, conf);
}

});

if( conf.modules != '' ) {
Expand Down