Skip to content

Commit

Permalink
Fixed border color reset bug, and modules can now be loaded from remo…
Browse files Browse the repository at this point in the history
…te websites
  • Loading branch information
victorjonsson committed Aug 18, 2013
1 parent 08dac15 commit 57f7671
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 55 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@ it calls jQ func **$.formUtils.validateInput** to validate the single input when

## Changelog

#### 2.1.6
* Modules can now be loaded from remote website

#### 2.1.5
* Fixed language bug (issue #43 on github)
* Validation on server side is now triggered by the blur event
Expand Down
2 changes: 1 addition & 1 deletion form-validator/date.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* @website http://formvalidator.net/#location-validators
* @license Dual licensed under the MIT or GPL Version 2 licenses
* @version 2.1.5
* @version 2.1.6
*/
(function($) {

Expand Down
2 changes: 1 addition & 1 deletion form-validator/file.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* @website http://formvalidator.net/
* @license Dual licensed under the MIT or GPL Version 2 licenses
* @version 2.1.5
* @version 2.1.6
*/
(function($, window) {

Expand Down
1 change: 0 additions & 1 deletion form-validator/form-test.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="jquery.form-validator.js"></script>
<script src="//code.jquery.com/qunit/qunit-1.12.0.js"></script>
<script>
(function($) {

Expand Down
62 changes: 17 additions & 45 deletions form-validator/jquery.form-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @website http://formvalidator.net/
* @license Dual licensed under the MIT or GPL Version 2 licenses
* @version 2.1.5
* @version 2.1.6
*/
(function($) {

Expand Down Expand Up @@ -90,9 +90,6 @@
config = $.extend($.formUtils.defaultConfig(), config || {});
config.errorMessagePosition = 'element';

// Capture default error message
//$.formUtils.figureOutDefaultBorderColor(this);

var $element = this,

// test if there is custom obj to hold element error msg (id = element name + err_msg)
Expand All @@ -110,6 +107,7 @@
// Remove possible error style applied by previous validation
$element
.removeClass(config.errorElementClass)
.css('border-color', '')
.parent()
.find('.'+config.errorMessageClass).remove();

Expand All @@ -121,10 +119,6 @@
elementErrMsgObj.innerHTML = '';
}

//if(config.borderColorOnError !== '') {
// $element.css('border-color', $.formUtils.defaultBorderColor);
//}

var validation = $.formUtils.validateInput($element, language, config, $form);

if(validation === true) {
Expand Down Expand Up @@ -246,9 +240,6 @@
var elementType = $element.attr('type');
if (!ignoreInput($element.attr('name'), elementType)) {

// memorize border color
// $.formUtils.figureOutDefaultBorderColor($element);

var validation = $.formUtils.validateInput(
$element,
language,
Expand All @@ -272,14 +263,10 @@
//
// Reset style and remove error class
//
//var borderStyleProp = $.formUtils.defaultBorderColor===null ||
// ($.formUtils.defaultBorderColor.indexOf(' ') > -1 && $.formUtils.defaultBorderColor.indexOf('rgb') == -1)
// ? 'border':'border-color';

$form.find('.has-error').removeClass('has-error');
$form.find('input,textarea,select')
//.css(borderStyleProp, $.formUtils.defaultBorderColor)
.css('border-color', '')
.removeClass(config.errorElementClass);
$form.find('.has-error').removeClass('has-error');

//
// Remove possible error messages from last validation
Expand Down Expand Up @@ -494,22 +481,6 @@
}
},

/**
* @param {jQuery} $element
*/
figureOutDefaultBorderColor : function($element) {
var elementType = $element.attr('type');
if (this.defaultBorderColor === null && elementType !== 'submit' && elementType !== 'checkbox' && elementType !== 'radio') {
this.defaultBorderColor = $element.css('border-color');
}
},

/**
* Default border color, will be picked up first
* time form is validated
*/
defaultBorderColor : null,

/**
* Available validators
*/
Expand Down Expand Up @@ -615,26 +586,27 @@
$.formUtils.isLoadingModules = true;
}

var cacheSuffix = '?__='+( new Date().getTime() ),
appendToElement = document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0];

$.each(moduleList, function(i, modName) {
modName = $.trim(modName);
if( modName.length == 0 ) {
moduleLoadedCallback();
}
else {
var scriptUrl = path + modName + (modName.substr(-3) == '.js' ? '':'.js');
$.ajax({
url : scriptUrl,
cache : scriptUrl.substr(-7) != '.dev.js',
dataType : 'script',
async : false,
success : function() {
var scriptUrl = path + modName + (modName.substr(-3) == '.js' ? '':'.js'),
script = document.createElement('SCRIPT');
script.type = 'text/javascript';
script.onload = moduleLoadedCallback;
script.src = scriptUrl + ( scriptUrl.substr(-7) == '.dev.js' ? cacheSuffix:'' );
script.onreadystatechange = function() {
// IE 7 fix
if( this.readyState == 'complete' ) {
moduleLoadedCallback();
},
error : function() {
moduleLoadedCallback();
throw new Error('Unable to load form validation module '+modName);
}
});
};
appendToElement.appendChild( script );
}
});
};
Expand Down
4 changes: 2 additions & 2 deletions form-validator/jquery.form-validator.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion form-validator/location.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* @website http://formvalidator.net/#location-validators
* @license Dual licensed under the MIT or GPL Version 2 licenses
* @version 2.1.5
* @version 2.1.6
*/
(function($) {

Expand Down
2 changes: 1 addition & 1 deletion form-validator/security.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* @website http://formvalidator.net/#security-validators
* @license Dual licensed under the MIT or GPL Version 2 licenses
* @version 2.1.5
* @version 2.1.6
*/
(function($) {

Expand Down
2 changes: 1 addition & 1 deletion form-validator/sweden.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* @website http://formvalidator.net/#swedish-validators
* @license Dual licensed under the MIT or GPL Version 2 licenses
* @version 2.1.5
* @version 2.1.6
*/
(function($, window) {

Expand Down
2 changes: 1 addition & 1 deletion form-validator/uk.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* @website http://formvalidator.net/#uk-validators
* @license Dual licensed under the MIT or GPL Version 2 licenses
* @version 2.1.5
* @version 2.1.6
*/
$.formUtils.addValidator({
name : 'ukvatnumber',
Expand Down
2 changes: 1 addition & 1 deletion formvalidator.jquery.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"validation",
"validator"
],
"version" : "2.1.5",
"version" : "2.1.6",
"author" : {
"name": "Victor Jonsson",
"url": "http://victorjonsson.se",
Expand Down

0 comments on commit 57f7671

Please sign in to comment.