Skip to content

Commit 92b05fa

Browse files
committed
Merge pull request victorjonsson#19 from stevewasiura/patch-5
doValidate, allow custom err msg container per element
2 parents 46c9242 + 8a92153 commit 92b05fa

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

jquery.formvalidator.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@
8484
}
8585

8686
var $element = $(this);
87-
87+
// test if there is custom obj to hold element error msg (id = element name + err_msg)
88+
var elementErrMsgObj = document.getElementById($element.attr('name')+'_err_msg');
89+
8890
var config = {
8991
ignore : [], // Names of inputs not to be validated, overwriting attribute notaed validation
9092
validationRuleAttribute : 'data-validation',
@@ -115,6 +117,11 @@
115117
.parent()
116118
.find('.jquery_form_error_message').remove();
117119

120+
// if element has custom err msg container, clear it
121+
if( elementErrMsgObj != null) {
122+
elementErrMsgObj.innerHTML = '';
123+
}
124+
118125
if(config.borderColorOnError !== '') {
119126
$element.css('border-color', jQueryFormUtils.defaultBorderColor);
120127
}
@@ -125,10 +132,13 @@
125132
if(validation === true) {
126133
$element.unbind('keyup');
127134
} else {
128-
$element
129-
.addClass(config.errorElementClass)
130-
.parent()
131-
.append('<span class="jquery_form_error_message">'+validation+'</span>');
135+
$element.addClass(config.errorElementClass);
136+
// if element has custom err msg container, use it
137+
if( elementErrMsgObj != null) {
138+
elementErrMsgObj.innerHTML = validation;
139+
} else { // use regular span append
140+
$element.parent().append('<span class="jquery_form_error_message">'+validation+'</span>');
141+
}
132142

133143
if(config.borderColorOnError !== '') {
134144
$element.css('border-color', config.borderColorOnError);

0 commit comments

Comments
 (0)