Skip to content

Commit 7221be9

Browse files
committed
Now properly finds the parent containers of inputs
1 parent 831a64a commit 7221be9

11 files changed

+46
-41
lines changed

form-validator/date.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @website http://formvalidator.net/#location-validators
1212
* @license Dual licensed under the MIT or GPL Version 2 licenses
13-
* @version 2.2.beta.62
13+
* @version 2.2.beta.65
1414
*/
1515
(function($) {
1616

form-validator/file.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @website http://formvalidator.net/
1212
* @license Dual licensed under the MIT or GPL Version 2 licenses
13-
* @version 2.2.beta.62
13+
* @version 2.2.beta.65
1414
*/
1515
(function($, window) {
1616

form-validator/form-test.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,12 @@
8181

8282
<div class="form-group">
8383
<label class="control-label" for="country-suggestions">Swedish county suggestions</label>
84-
<input name="Swedish county suggestion" data-validation="swecounty" type="text" id="swedish-county-suggestions" class="form-control" />
84+
<div>
85+
<div>
86+
<!-- Make sure error class "has-error" gets all the way up to .form-group -->
87+
<input name="Swedish county suggestion" data-validation="swecounty" type="text" id="swedish-county-suggestions" class="form-control" />
88+
</div>
89+
</div>
8590
</div>
8691

8792
<div class="form-group">

form-validator/html5.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
* @website http://formvalidator.net/
1919
* @license Dual licensed under the MIT or GPL Version 2 licenses
20-
* @version 2.2.beta.62
20+
* @version 2.2.beta.65
2121
*/
2222
(function($, window) {
2323

form-validator/jquery.form-validator.js

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,30 @@
55
*
66
* @website http://formvalidator.net/
77
* @license Dual licensed under the MIT or GPL Version 2 licenses
8-
* @version 2.2.beta.62
8+
* @version 2.2.beta.65
99
*/
1010
(function($) {
1111

1212
'use strict';
1313

1414
var $window = $(window),
15+
_getInputParentContainer = function($elem) {
16+
var $parent = $elem.parent();
17+
if( !$parent.hasClass('form-group') ) {
18+
var $formGroup = $parent.closest('.form-group');
19+
if( $formGroup.length ) {
20+
return $formGroup.eq(0);
21+
}
22+
}
23+
return $parent;
24+
},
1525
_applyErrorStyle = function($elem, conf) {
1626
$elem
1727
.addClass(conf.errorElementClass)
1828
.removeClass('valid');
1929

20-
var $parent = $elem.parent();
21-
if($parent.hasClass("input-group"))
22-
$parent = $parent.parent();
23-
24-
$parent
25-
.addClass(conf.inputParentClassOnError)
30+
_getInputParentContainer($elem)
31+
.addClass(conf.inputParentClassOnError)
2632
.removeClass(conf.inputParentClassOnSuccess);
2733

2834
if(conf.borderColorOnError !== '') {
@@ -31,11 +37,7 @@
3137
},
3238
_removeErrorStyle = function($elem, conf) {
3339
$elem.each(function() {
34-
var $this = $(this),
35-
$parent = $this.parent();
36-
37-
if($parent.hasClass("input-group"))
38-
$parent = $parent.parent();
40+
var $this = $(this);
3941

4042
_setInlineErrorMessage($this, '', conf, conf.errorMessagePosition);
4143

@@ -44,9 +46,9 @@
4446
.removeClass(conf.errorElementClass)
4547
.css('border-color', '');
4648

47-
$parent
49+
_getInputParentContainer($this)
4850
.removeClass(conf.inputParentClassOnError)
49-
.removeClass(conf.inputParentClassOnSuccess)
51+
.removeClass(conf.inputParentClassOnSuccess)
5052
.find('.'+conf.errorMessageClass) // remove inline span holding error message
5153
.remove();
5254
});
@@ -78,14 +80,15 @@
7880
}
7981
}
8082
else {
81-
var $parent = $input.parent();
82-
if($parent.hasClass("input-group")) $parent = $parent.parent();
83-
var $mess = $parent.find('.'+conf.errorMessageClass+'.help-block');
84-
if( $mess.length == 0 ) {
85-
$mess = $('<span></span>').addClass('help-block').addClass(conf.errorMessageClass);
86-
$mess.appendTo($parent);
87-
}
88-
$mess.html(mess);
83+
84+
var $parent = _getInputParentContainer($input),
85+
$mess = $parent.find('.'+conf.errorMessageClass+'.help-block');
86+
87+
if( $mess.length == 0 ) {
88+
$mess = $('<span></span>').addClass('help-block').addClass(conf.errorMessageClass);
89+
$mess.appendTo($parent);
90+
}
91+
$mess.html(mess);
8992
}
9093
},
9194
_getInlineErrorElement = function($input, conf) {
@@ -249,11 +252,8 @@
249252
);
250253

251254
if(validation === true) {
252-
$elem
253-
.addClass('valid')
254-
.parent()
255-
.addClass(conf.inputParentClassOnSuccess);
256-
255+
$elem.addClass('valid');
256+
_getInputParentContainer($elem).addClass(conf.inputParentClassOnSuccess);
257257
} else if(validation !== null) {
258258

259259
_applyErrorStyle($elem, conf);
@@ -397,9 +397,9 @@
397397
} else {
398398
$elem
399399
.valAttr('current-error', false)
400-
.addClass('valid')
401-
.parent()
402-
.addClass('has-success');
400+
.addClass('valid');
401+
402+
_getInputParentContainer($elem).addClass(conf.inputParentClassOnSuccess);
403403
}
404404
}
405405
}

form-validator/jquery.form-validator.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

form-validator/jsconf.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* @website http://formvalidator.net/#location-validators
99
* @license Dual licensed under the MIT or GPL Version 2 licenses
10-
* @version 2.2.beta.62
10+
* @version 2.2.beta.65
1111
*/
1212
(function($) {
1313

form-validator/location.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @website http://formvalidator.net/#location-validators
1212
* @license Dual licensed under the MIT or GPL Version 2 licenses
13-
* @version 2.2.beta.62
13+
* @version 2.2.beta.65
1414
*/
1515
(function($) {
1616

form-validator/security.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* - cvv
1414
*
1515
* @website http://formvalidator.net/#security-validators
16-
* @version 2.2.beta.62
16+
* @version 2.2.beta.65
1717
*/
1818
(function($, window) {
1919

form-validator/sweden.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
* @website http://formvalidator.net/#swedish-validators
1515
* @license Dual licensed under the MIT or GPL Version 2 licenses
16-
* @version 2.2.beta.62
16+
* @version 2.2.beta.65
1717
*/
1818
(function($, window) {
1919

form-validator/uk.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* @website http://formvalidator.net/#uk-validators
1111
* @license Dual licensed under the MIT or GPL Version 2 licenses
12-
* @version 2.2.beta.62
12+
* @version 2.2.beta.65
1313
*/
1414
$.formUtils.addValidator({
1515
name : 'ukvatnumber',

0 commit comments

Comments
 (0)