Skip to content

Commit 4f1bda5

Browse files
author
Matthew Hailwood
committed
Added ability to adjust what element a fields prompt is shown on (useful for when hidden inputs are set to validate) by supplying either an ID in the data-jqv-prompt-at data attribute, or using jQuery's .data( method and supplying a jQuery object e.g. .data('jqv-prompt-at', );
1 parent 376386f commit 4f1bda5

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

js/jquery.validationEngine.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,18 @@
342342
errorFound |= methods._validateField(field, options);
343343
if (errorFound && first_err==null)
344344
if (field.is(":hidden") && options.prettySelect)
345-
first_err = field = form.find("#" + options.usePrefix + methods._jqSelector(field.attr('id')) + options.useSuffix);
346-
else
347-
first_err=field;
345+
first_err = field = form.find("#" + options.usePrefix + methods._jqSelector(field.attr('id')) + options.useSuffix);
346+
else {
347+
348+
//Check if we need to adjust what element to show the prompt on
349+
//and and such scroll to instead
350+
if(field.data('jqv-prompt-at') instanceof jQuery ){
351+
field = field.data('jqv-prompt-at');
352+
} else if(field.data('jqv-prompt-at')) {
353+
field = $(field.data('jqv-prompt-at'));
354+
}
355+
first_err=field;
356+
}
348357
if (options.doNotShowAllErrosOnSubmit)
349358
return false;
350359
names.push(field.attr('name'));
@@ -1510,6 +1519,13 @@
15101519
* @param {Map} options user options
15111520
*/
15121521
_showPrompt: function(field, promptText, type, ajaxed, options, ajaxform) {
1522+
//Check if we need to adjust what element to show the prompt on
1523+
if(field.data('jqv-prompt-at') instanceof jQuery ){
1524+
field = field.data('jqv-prompt-at');
1525+
} else if(field.data('jqv-prompt-at')) {
1526+
field = $(field.data('jqv-prompt-at'));
1527+
}
1528+
15131529
var prompt = methods._getPrompt(field);
15141530
// The ajax submit errors are not see has an error in the form,
15151531
// When the form errors are returned, the engine see 2 bubbles, but those are ebing closed by the engine at the same time

0 commit comments

Comments
 (0)