Skip to content

Commit 4c19908

Browse files
author
Richard Thompson
committed
Allow custom HTML attribute "data-required-class" to override formError prompt class.
I was doing a project where I needed multi-tiered required fields. So "red" was for primary then make more classes for "secondary / tertiary" etc. So that when the whole form was validated, the "required" alerts were all different depending on the class defined in the "data-required-class" attribute. Thought it might be useful to others as well. Also added in support for prettySelect.
1 parent 8b0f310 commit 4c19908

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

js/jquery.validationEngine.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,6 +1581,21 @@
15811581
if (options.addPromptClass)
15821582
prompt.addClass(options.addPromptClass);
15831583

1584+
// Add custom prompt class defined in element
1585+
var requiredOverride = field.attr('data-required-class');
1586+
if(requiredOverride !== undefined) {
1587+
prompt.addClass(requiredOverride);
1588+
} else {
1589+
if(options.prettySelect) {
1590+
if($('#' + field.attr('id')).next().is('select')) {
1591+
var prettyOverrideClass = $('#' + field.attr('id').substr(options.usePrefix.length).substring(options.useSuffix.length)).attr('data-required-class');
1592+
if(prettyOverrideClass !== undefined) {
1593+
prompt.addClass(prettyOverrideClass);
1594+
}
1595+
}
1596+
}
1597+
}
1598+
15841599
prompt.css({
15851600
"opacity": 0
15861601
});

0 commit comments

Comments
 (0)