Skip to content

Commit de90627

Browse files
committed
now supporting horizontal forms, issue victorjonsson#266
1 parent bc920b6 commit de90627

18 files changed

+138
-133
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.37
13+
* @version 2.2.39
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/#file-validators
1212
* @license Dual licensed under the MIT or GPL Version 2 licenses
13-
* @version 2.2.37
13+
* @version 2.2.39
1414
*/
1515
(function($, window) {
1616

form-validator/form-test.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@
282282
<h2>HTML5 attributes</h2>
283283
<div class="form-group">
284284
<label class="control-label">type="email"</label>
285-
<input type="text" required="required" list="da-mejl" />
285+
<input type="email" required="required" list="da-mejl" />
286286
<datalist id="da-mejl">
287287
<option value="Test">Test</option>
288288
<option value="test2">test2</option>
@@ -344,7 +344,7 @@ <h2>HTML5 attributes</h2>
344344
errorMessageKey: 'badEvenNumber'
345345
});
346346

347-
window.applyValidation = function(validateOnBlur, forms, messagePosition) {
347+
window.applyValidation = function(validateOnBlur, forms, messagePosition, xtraModule) {
348348
if( !forms )
349349
forms = 'form';
350350
if( !messagePosition )
@@ -360,7 +360,7 @@ <h2>HTML5 attributes</h2>
360360
scrollToTopOnError : true,
361361
lang : 'sv',
362362
// borderColorOnError : 'purple',
363-
modules : 'security'+dev+', location'+dev+', sweden'+dev+', html5'+dev+', file'+dev+', uk'+dev,
363+
modules : 'security'+dev+', location'+dev+', sweden'+dev+', file'+dev+', uk'+dev +( xtraModule ? ','+xtraModule:''),
364364
onModulesLoaded: function() {
365365
$('#country-suggestions').suggestCountry();
366366
$('#swedish-county-suggestions').suggestSwedishCounty();
@@ -393,7 +393,7 @@ <h2>HTML5 attributes</h2>
393393
window.applyValidation(true, '#form-a', 'top');
394394
window.applyValidation(false, '#form-b', 'element');
395395
window.applyValidation(true, '#form-c', $('#error-container'));
396-
window.applyValidation(true, '#form-d', 'element');
396+
window.applyValidation(true, '#form-d', 'element', 'html5'+dev);
397397

398398
// Load one module outside $.validate() even though you do not have to
399399
$.formUtils.loadModules('date'+dev+'.js', false, false);

form-validator/html5.dev.js

Lines changed: 114 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -17,143 +17,147 @@
1717
*
1818
* @website http://formvalidator.net/
1919
* @license Dual licensed under the MIT or GPL Version 2 licenses
20-
* @version 2.2.37
20+
* @version 2.2.39
2121
*/
2222
(function($, window) {
2323

2424
"use strict";
2525

2626
var SUPPORTS_PLACEHOLDER = 'placeholder' in document.createElement('INPUT'),
27-
SUPPORTS_DATALIST = 'options' in document.createElement('DATALIST');
27+
SUPPORTS_DATALIST = 'options' in document.createElement('DATALIST'),
28+
hasLoadedDateModule = false,
29+
setupValidationUsingHTML5Attr = function($form) {
2830

29-
$(window).bind('validatorsLoaded formValidationSetup', function(evt, $form) {
30-
31-
if( !$form ) {
32-
$form = $('form');
33-
}
34-
35-
var hasLoadedDateModule = false;
36-
37-
$form.each(function() {
31+
$form.each(function() {
3832
var $f = $(this),
39-
$formInputs = $f.find('input,textarea,select'),
40-
foundHtml5Rule = false;
33+
$formInputs = $f.find('input,textarea,select'),
34+
foundHtml5Rule = false;
4135

4236
$formInputs.each(function() {
43-
var validation = [],
44-
$input = $(this),
45-
isRequired = $input.attr('required'),
46-
attrs = {};
47-
48-
switch ( ($input.attr('type') || '').toLowerCase() ) {
49-
case 'time':
50-
validation.push('time');
51-
if( !$.formUtils.validators.validate_date && !hasLoadedDateModule ) {
52-
hasLoadedDateModule = true;
53-
$.formUtils.loadModules('date');
54-
}
55-
break;
56-
case 'url':
57-
validation.push('url');
58-
break;
59-
case 'email':
60-
validation.push('email');
61-
break;
62-
case 'date':
63-
validation.push('date');
64-
break;
65-
case 'number':
66-
validation.push('number');
67-
var max = $input.attr('max'),
68-
min = $input.attr('min');
69-
if( min || max ) {
70-
if( !min )
71-
min = '0';
72-
if( !max )
73-
max = '9007199254740992'; // js max int
74-
75-
attrs['data-validation-allowing'] = 'range['+min+';'+max+']';
76-
if( min.indexOf('-') === 0 || max.indexOf('-') === 0 ) {
77-
attrs['data-validation-allowing'] += ',negative';
78-
}
79-
if( min.indexOf('.') > -1 || max.indexOf('.') > -1 ) {
80-
attrs['data-validation-allowing'] += ',float';
81-
}
82-
}
83-
break;
84-
}
37+
var validation = [],
38+
$input = $(this),
39+
isRequired = $input.attr('required'),
40+
attrs = {};
41+
42+
switch ( ($input.attr('type') || '').toLowerCase() ) {
43+
case 'time':
44+
validation.push('time');
45+
if( !$.formUtils.validators.validate_date && !hasLoadedDateModule ) {
46+
hasLoadedDateModule = true;
47+
$.formUtils.loadModules('date');
48+
}
49+
break;
50+
case 'url':
51+
validation.push('url');
52+
break;
53+
case 'email':
54+
validation.push('email');
55+
break;
56+
case 'date':
57+
validation.push('date');
58+
break;
59+
case 'number':
60+
validation.push('number');
61+
var max = $input.attr('max'),
62+
min = $input.attr('min');
63+
if( min || max ) {
64+
if( !min )
65+
min = '0';
66+
if( !max )
67+
max = '9007199254740992'; // js max int
68+
69+
attrs['data-validation-allowing'] = 'range['+min+';'+max+']';
70+
if( min.indexOf('-') === 0 || max.indexOf('-') === 0 ) {
71+
attrs['data-validation-allowing'] += ',negative';
72+
}
73+
if( min.indexOf('.') > -1 || max.indexOf('.') > -1 ) {
74+
attrs['data-validation-allowing'] += ',float';
75+
}
76+
}
77+
break;
78+
}
79+
80+
if( $input.attr('pattern') ) {
81+
validation.push('custom');
82+
attrs['data-validation-regexp'] = $input.attr('pattern');
83+
}
84+
if( $input.attr('maxlength') ) {
85+
validation.push('length');
86+
attrs['data-validation-length'] = 'max'+$input.attr('maxlength');
87+
}
88+
89+
if( !SUPPORTS_DATALIST && $input.attr('list') ) {
90+
var suggestions = [],
91+
$list = $('#'+$input.attr('list'));
92+
93+
$list.find('option').each(function() {
94+
suggestions.push($(this).text());
95+
});
8596

86-
if( $input.attr('pattern') ) {
87-
validation.push('custom');
88-
attrs['data-validation-regexp'] = $input.attr('pattern');
97+
if( suggestions.length == 0 ) {
98+
// IE fix
99+
var opts = $.trim($('#'+$input.attr('list')).text()).split('\n');
100+
$.each(opts, function(i, option) {
101+
suggestions.push($.trim(option));
102+
});
89103
}
90-
if( $input.attr('maxlength') ) {
91-
validation.push('length');
92-
attrs['data-validation-length'] = 'max'+$input.attr('maxlength');
93-
}
94-
95-
if( !SUPPORTS_DATALIST && $input.attr('list') ) {
96-
var suggestions = [],
97-
$list = $('#'+$input.attr('list'));
98104

99-
$list.find('option').each(function() {
100-
suggestions.push($(this).text());
101-
});
105+
$list.remove();
102106

103-
if( suggestions.length == 0 ) {
104-
// IE fix
105-
var opts = $.trim($('#'+$input.attr('list')).text()).split('\n');
106-
$.each(opts, function(i, option) {
107-
suggestions.push($.trim(option));
108-
});
109-
}
107+
$.formUtils.suggest( $input, suggestions );
108+
}
110109

111-
$list.remove();
110+
if( isRequired && validation.length == 0 )
111+
validation.push('required');
112112

113-
$.formUtils.suggest( $input, suggestions );
113+
if( validation.length ) {
114+
if( !isRequired ) {
115+
attrs['data-validation-optional'] = 'true';
114116
}
115117

116-
if( isRequired && validation.length == 0 )
117-
validation.push('required');
118+
foundHtml5Rule = true;
119+
$input.attr('data-validation', validation.join(' '));
118120

119-
if( validation.length ) {
120-
if( !isRequired ) {
121-
attrs['data-validation-optional'] = 'true';
122-
}
123-
124-
foundHtml5Rule = true;
125-
$input.attr('data-validation', validation.join(' '));
126-
127-
$.each(attrs, function(attrName, attrVal) {
128-
$input.attr(attrName, attrVal);
129-
});
130-
}
121+
$.each(attrs, function(attrName, attrVal) {
122+
$input.attr(attrName, attrVal);
123+
});
124+
}
131125
});
132126

133127
if( foundHtml5Rule ) {
134-
$f.trigger('html5ValidationAttrsFound');
128+
$f.trigger('html5ValidationAttrsFound');
135129
}
136130

137131
if( !SUPPORTS_PLACEHOLDER ) {
138-
$formInputs.filter('input[placeholder]').each(function() {
139-
this.defaultValue = this.getAttribute('placeholder');
140-
$(this)
141-
.bind('focus', function() {
142-
if(this.value == this.defaultValue) {
143-
this.value = '';
144-
$(this).removeClass('showing-placeholder');
145-
}
146-
})
147-
.bind('blur', function() {
148-
if($.trim(this.value) == '') {
149-
this.value = this.defaultValue;
150-
$(this).addClass('showing-placeholder');
151-
}
152-
});
153-
});
132+
$formInputs.filter('input[placeholder]').each(function() {
133+
this.defaultValue = this.getAttribute('placeholder');
134+
$(this)
135+
.bind('focus', function() {
136+
if(this.value == this.defaultValue) {
137+
this.value = '';
138+
$(this).removeClass('showing-placeholder');
139+
}
140+
})
141+
.bind('blur', function() {
142+
if($.trim(this.value) == '') {
143+
this.value = this.defaultValue;
144+
$(this).addClass('showing-placeholder');
145+
}
146+
});
147+
});
154148
}
155149

156-
});
150+
});
151+
};
152+
153+
$(window).bind('validatorsLoaded formValidationSetup', function(evt, $form) {
154+
if( !$form ) {
155+
$form = $('form');
156+
}
157+
setupValidationUsingHTML5Attr($form);
157158
});
158159

160+
// Make this method available outside the module
161+
$.formUtils.setupValidationUsingHTML5Attr = setupValidationUsingHTML5Attr;
162+
159163
})(jQuery, window);

form-validator/html5.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

form-validator/jquery.form-validator.js

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

@@ -17,7 +17,7 @@
1717
return $($elem.valAttr('error-msg-container'));
1818
} else {
1919
var $parent = $elem.parent();
20-
if (!$parent.hasClass('form-group')) {
20+
if ( !$parent.hasClass('form-group') && !$parent.closest('form').hasClass('form-horizontal') ) {
2121
var $formGroup = $parent.closest('.form-group');
2222
if ($formGroup.length) {
2323
return $formGroup.eq(0);
@@ -791,6 +791,7 @@
791791
}
792792
};
793793

794+
794795
if (numModules > 0) {
795796
$.formUtils.isLoadingModules = true;
796797
}

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

Lines changed: 3 additions & 3 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.37
10+
* @version 2.2.39
1111
*/
1212
(function($) {
1313

form-validator/lang/de.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* @website http://formvalidator.net/
88
* @license Dual licensed under the MIT or GPL Version 2 licenses
9-
* @version 2.2.37
9+
* @version 2.2.39
1010
*/
1111
(function($, window) {
1212

form-validator/lang/es.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* @website http://formvalidator.net/
88
* @license Dual licensed under the MIT or GPL Version 2 licenses
9-
* @version 2.2.37
9+
* @version 2.2.39
1010
*/
1111
(function($, window) {
1212

form-validator/lang/fr.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* @website http://formvalidator.net/
88
* @license Dual licensed under the MIT or GPL Version 2 licenses
9-
* @version 2.2.37
9+
* @version 2.2.39
1010
*/
1111
(function($, window) {
1212

form-validator/lang/sv.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* @website http://formvalidator.net/
88
* @license Dual licensed under the MIT or GPL Version 2 licenses
9-
* @version 2.2.37
9+
* @version 2.2.39
1010
*/
1111
(function($, window) {
1212

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.37
13+
* @version 2.2.39
1414
*/
1515
(function($) {
1616

0 commit comments

Comments
 (0)