-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from peckadesign/scroll-error-into-view
#1 Úprava scrollování po validování formuláře
- Loading branch information
Showing
2 changed files
with
29 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
"name": "pd-forms", | ||
"title": "pdForms", | ||
"description": "Customization of netteForms for use in PeckaDesign.", | ||
"version": "4.0.1", | ||
"version": "4.1.0", | ||
"author": "PeckaDesign, s.r.o <[email protected]>", | ||
"contributors": [ | ||
"Radek Šerý <[email protected]>", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/** | ||
* @name pdForms | ||
* @author Radek Šerý <[email protected]> | ||
* @version 4.0.1 | ||
* @version 4.1.0 | ||
* | ||
* Features: | ||
* - live validation | ||
|
@@ -594,6 +594,31 @@ | |
} | ||
|
||
|
||
/** | ||
* 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 | ||
* validating. This means removing all properties but data from arg and storing them elsewhere. | ||
|
@@ -644,8 +669,8 @@ | |
} | ||
} | ||
|
||
if (focusElem) { | ||
focusElem.focus(); | ||
if (errors.length) { | ||
pdForms.afterValidationScroll(form, focusElem); | ||
} | ||
}; | ||
|
||
|