Skip to content

Commit

Permalink
Oprava inicializace formulářů. Původní metodu Nette.initForm chceme…
Browse files Browse the repository at this point in the history
… volat vždy. Sama o sobě obsahuje kontrolu na opětovnou inicializaci, na začátku ale ještě spouští nastavení, které je nutné udělat i po ajaxu (jmenovitě inicializace toggle elementů). Metoda `Nette.toggleControl` je pak v Nette ošetřená proti vícenásobnému navázání handleru pomocí weakMap.
  • Loading branch information
zipper committed Sep 4, 2024
1 parent 3d675c4 commit 60489a6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "pd-forms",
"title": "pdForms",
"description": "Customization of netteForms for use in PeckaDesign.",
"version": "4.1.1",
"version": "4.1.2",
"author": "PeckaDesign, s.r.o <[email protected]>",
"contributors": [
"Radek Šerý <[email protected]>",
Expand Down
14 changes: 9 additions & 5 deletions src/assets/pdForms.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @name pdForms
* @author Radek Šerý <[email protected]>
* @version 4.1.1
* @version 4.1.2
*
* Features:
* - live validation
Expand Down Expand Up @@ -45,7 +45,7 @@

var pdForms = window.pdForms || {};

pdForms.version = '4.1.1';
pdForms.version = '4.1.2';


/**
Expand Down Expand Up @@ -156,8 +156,11 @@
}
}


// TODO pokud je alespoň jeden z group focusovaný, tak chceme validovat přímo všechny?
// Pokud totiž mají společnou validaci a při odeslání se začervení, pak při opravě jednoho by měla zmizet chyba všude, např. pokud je podmínka pro jeden nebo druhý input
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
// prevents flashing of message, when ajax rule is evaluated - ajax rules removes their messages when the ajax
// rule is evaluated
Expand Down Expand Up @@ -712,13 +715,14 @@
* Setup handlers.
*/
Nette.initForm = function (form) {
// Always call the original `initForm` method. This method handles already initialised forms itself.
pdForms.Nette.initForm(form);

// Skip already initialized forms
if (form.noValidate) {
return;
}

pdForms.Nette.initForm(form);

addDelegatedEventListener(form, 'focusout change', 'select, textarea, input:not([type="submit"]):not([type="reset"])', setEverFocused);

addDelegatedEventListener(form, 'validate focusout', 'textarea, input:not([type="submit"]):not([type="reset"]):not([type="checkbox"]):not([type="radio"]):not([type="file"])', pdForms.liveValidation);
Expand Down

0 comments on commit 60489a6

Please sign in to comment.