Skip to content

Commit 2f7b3f5

Browse files
committed
Fix for issue victorjonsson#82
1 parent 8b082bf commit 2f7b3f5

File tree

10 files changed

+61
-19
lines changed

10 files changed

+61
-19
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ it calls jQ func **$.formUtils.validateInput** to validate the single input when
299299
* Incorrect error-styling of select elements is now fixed
300300
* Deprecated function $.validationSetup is now removed, use $.validate() instead
301301
* You can now return an array with errors using the event `onValidate`
302+
* You can now declare an element where all error messages should be placed (config.errorMessagePosition)
302303

303304
#### 2.1.36
304305
* Now possible to use the native reset() function to clear error messages and error styling of the input elements

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.1.45
13+
* @version 2.1.46
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.1.45
13+
* @version 2.1.46
1414
*/
1515
(function($, window) {
1616

form-validator/form-test.html

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@
4949
color: #999 !important;
5050
}
5151

52+
/* Error container for form C */
53+
54+
#error-container div {
55+
color: red;
56+
line-height: 140%;
57+
}
58+
59+
#error-container div:last-child {
60+
padding-bottom: 10px;
61+
}
62+
5263
</style>
5364
</head>
5465
<body>
@@ -215,6 +226,10 @@
215226
<label class="control-label">Country</label>
216227
<input name="test" data-validation="country" data-validation-error-msg="No valid country given" />
217228
</div>
229+
<div class="form-group">
230+
<label class="control-label">E-mail</label>
231+
<input name="test" data-validation="email" data-validation-error-msg="E-mail is not valid" />
232+
</div>
218233
<div class="form-group">
219234
<label class="control-label">Alphanumeric (will only be validated if the checkbox is checked)</label>
220235
<input name="test2"
@@ -223,6 +238,9 @@
223238
data-validation-if-checked="checker" />
224239
<br />
225240
<input type="checkbox" name="checker" />
241+
</div>
242+
<div id="error-container">
243+
226244
</div>
227245
<p>
228246
<input type="submit" class="button">
@@ -300,8 +318,8 @@
300318
$('#text-area').restrictLength($('#max-len'));
301319

302320
window.applyValidation(true);
303-
window.applyValidation(false, '#form-b');
304-
window.applyValidation(true, '#form-c', 'element');
321+
window.applyValidation(false, '#form-b', 'element');
322+
window.applyValidation(true, '#form-c', $('#error-container'));
305323

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

form-validator/jquery.form-validator.js

Lines changed: 31 additions & 9 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.1.45
8+
* @version 2.1.46
99
*/
1010
(function($) {
1111

@@ -25,7 +25,7 @@
2525
},
2626
_removeErrorStyle = function($elem, conf) {
2727
$elem.each(function() {
28-
_setInlineErrorMessage($(this), '', conf);
28+
_setInlineErrorMessage($(this), '', conf, conf.errorMessagePosition);
2929
$(this)
3030
.removeClass('valid')
3131
.removeClass(conf.errorElementClass)
@@ -37,11 +37,32 @@
3737
.remove();
3838
});
3939
},
40-
_setInlineErrorMessage = function($input, mess, conf) {
40+
_setInlineErrorMessage = function($input, mess, conf, $messageContainer) {
4141
var custom = _getInlineErrorElement($input);
4242
if( custom ) {
4343
custom.innerHTML = mess;
44-
} else {
44+
}
45+
else if( typeof $messageContainer == 'object' ) {
46+
var $found = false;
47+
$messageContainer.find('.'+conf.errorMessageClass).each(function() {
48+
if( this.inputReferer == $input[0] ) {
49+
$found = $(this);
50+
return false;
51+
}
52+
});
53+
if( $found ) {
54+
if( !mess ) {
55+
$found.remove();
56+
} else {
57+
$found.html(mess);
58+
}
59+
} else {
60+
var $mess = $('<div class="'+conf.errorMessageClass+'">'+mess+'</div>');
61+
$mess[0].inputReferer = $input[0];
62+
$messageContainer.prepend($mess);
63+
}
64+
}
65+
else {
4566
var $mess = $input.parent().find('.'+conf.errorMessageClass+'.help-block');
4667
if( $mess.length == 0 ) {
4768
$mess = $('<span></span>').addClass('help-block').addClass(conf.errorMessageClass);
@@ -207,7 +228,7 @@
207228
} else if(validation !== null) {
208229

209230
_applyErrorStyle($elem, conf);
210-
_setInlineErrorMessage($elem, validation, conf);
231+
_setInlineErrorMessage($elem, validation, conf, conf.errorMessagePosition);
211232

212233
if(attachKeyupEvent) {
213234
$elem.bind('keyup', function() {
@@ -329,7 +350,7 @@
329350
// Run validation callback
330351
if( typeof conf.onValidate == 'function' ) {
331352
var errors = conf.onValidate($form);
332-
if($.isArray(errors) ) {
353+
if( $.isArray(errors) ) {
333354
$.each(errors, function(i, err) {
334355
addErrorMessage(err.message, err.element);
335356
});
@@ -359,12 +380,13 @@
359380
}
360381
}
361382

362-
// Display error message below input field
363-
else {
383+
// Display error message below input field or in defined container
384+
else {
364385
$.each(errorInputs, function(i, $input) {
365-
_setInlineErrorMessage($input, $input.attr('current-error'), conf);
386+
_setInlineErrorMessage($input, $input.attr('current-error'), conf, conf.errorMessagePosition);
366387
});
367388
}
389+
368390
return false;
369391
}
370392

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

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

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

form-validator/security.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
* @website http://formvalidator.net/#security-validators
1414
* @license Dual licensed under the MIT or GPL Version 2 licenses
15-
* @version 2.1.45
15+
* @version 2.1.46
1616
*/
1717
(function($) {
1818

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.1.45
16+
* @version 2.1.46
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.1.45
12+
* @version 2.1.46
1313
*/
1414
$.formUtils.addValidator({
1515
name : 'ukvatnumber',

0 commit comments

Comments
 (0)