Comparing version
@@ -5,3 +5,3 @@ { | ||
"description": "Customization of netteForms for use in PeckaDesign.", | ||
"version": "4.0.1", | ||
"version": "4.1.0", | ||
"author": "PeckaDesign, s.r.o <support@peckadesign.cz>", | ||
@@ -8,0 +8,0 @@ "contributors": [ |
/** | ||
* @name pdForms | ||
* @author Radek Šerý <radek.sery@peckadesign.cz> | ||
* @version 4.0.1 | ||
* @version 4.1.0 | ||
* | ||
@@ -160,3 +160,3 @@ * Features: | ||
validate.forEach(function(elem) { | ||
if (elem.getAttribute('data-pdforms-ever-focused')) { | ||
if (elem.getAttribute('data-pdforms-ever-focused') || elem.value !== '') { | ||
// assumes the input is valid, therefore removing all messages except those associated with ajax rules; this | ||
@@ -599,2 +599,27 @@ // prevents flashing of message, when ajax rule is evaluated - ajax rules removes their messages when the ajax | ||
/** | ||
* Scroll into first error after validation. | ||
*/ | ||
pdForms.afterValidationScroll = function (form, firstErrorElem) { | ||
if (! firstErrorElem) { | ||
form.scrollIntoView(); | ||
return; | ||
} | ||
var placeholder = pdForms.getMessagePlaceholder(firstErrorElem) | ||
if (placeholder.isGlobal || firstErrorElem.type === 'hidden') { | ||
(placeholder.elem ?? form).scrollIntoView() | ||
firstErrorElem.focus({ | ||
preventScroll: true | ||
}); | ||
return; | ||
} | ||
firstErrorElem.focus() | ||
} | ||
/** | ||
* Optional rules are defined using "optional" property in "arg". We have to convert arg into Nette format before | ||
@@ -649,4 +674,4 @@ * validating. This means removing all properties but data from arg and storing them elsewhere. | ||
if (focusElem) { | ||
focusElem.focus(); | ||
if (errors.length) { | ||
pdForms.afterValidationScroll(form, focusElem); | ||
} | ||
@@ -653,0 +678,0 @@ }; |
@@ -0,0 +0,0 @@ /** |
95665
0.73%1068
1.71%