From 227893dff3f972e8d5c01056023807b343c42f69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radek=20=C5=A0er=C3=BD?= Date: Mon, 12 May 2025 10:57:44 +0200 Subject: [PATCH 1/2] =?UTF-8?q?Zpr=C3=A1vy=20se=20nyn=C3=AD=20nema=C5=BEou?= =?UTF-8?q?=20v=20r=C3=A1mci=20`validateControl`,=20ale=20p=C5=99i=20`vali?= =?UTF-8?q?dateForm`.=20P=C5=AFvodn=C3=AD=20=C3=BAprava=20=C5=99e=C5=A1ila?= =?UTF-8?q?=20probl=C3=A9m=20#58,=20nicm=C3=A9n=C4=9B=20zanesla=20chybu,?= =?UTF-8?q?=20kdy=20mohlo=20doj=C3=ADt=20k=20nezobrazen=C3=AD=20chyb.=20Po?= =?UTF-8?q?kud=20bylo=20po=20zobrazen=C3=AD=20chyby=20validov=C3=A1no=20da?= =?UTF-8?q?l=C5=A1=C3=AD=20pravidlo,=20jeho=C5=BE=20sou=C4=8D=C3=A1st?= =?UTF-8?q?=C3=AD=20byla=20podm=C3=ADnka=20(zano=C5=99en=C3=A9=20rules)=20?= =?UTF-8?q?a=20toto=20pravidlo=20bylo=20validn=C3=AD=20(respektive=20jeho?= =?UTF-8?q?=20prvn=C3=AD=20=C4=8D=C3=A1st=20-=20podm=C3=ADnka),=20do=C5=A1?= =?UTF-8?q?lo=20ke=20smaz=C3=A1n=C3=AD=20p=C5=AFvodn=C3=AD=20chyby.=20To?= =?UTF-8?q?=20bylo=20zp=C5=AFsobeno=20rekurzivn=C3=ADm=20vol=C3=A1n=C3=ADm?= =?UTF-8?q?=20`validateControl`.=20=C5=98e=C5=A1en=C3=AD=20je=20revert=20p?= =?UTF-8?q?=C5=AFvodn=C3=AD=20=C3=BApravy=20(nemazat=20zpr=C3=A1vy=20uvnit?= =?UTF-8?q?=C5=99=20validateControl)=20a=20z=C3=A1rove=C5=88=20p=C5=99et?= =?UTF-8?q?=C3=AD=C5=BEen=C3=AD=20`validateForm`,=20na=20jeho=C5=BE=20za?= =?UTF-8?q?=C4=8D=C3=A1tku=20sma=C5=BEeme=20zpr=C3=A1vy=20v=20cel=C3=A9m?= =?UTF-8?q?=20formul=C3=A1=C5=99i=20a=20pot=C3=A9=20teprve=20jej=20validuj?= =?UTF-8?q?eme.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/assets/pdForms.js | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/assets/pdForms.js b/src/assets/pdForms.js index 1c2748d..dd88223 100644 --- a/src/assets/pdForms.js +++ b/src/assets/pdForms.js @@ -54,7 +54,8 @@ pdForms.Nette = { validateControl: Nette.validateControl, toggleControl: Nette.toggleControl, - initForm: Nette.initForm + initForm: Nette.initForm, + validateForm: Nette.validateForm }; @@ -619,6 +620,26 @@ } + pdForms.removeFormMessages = function(form) { + var radios = {}; + + for (var i = 0; i < form.elements.length; i++) { + var elem = form.elements[i]; + + if (elem.tagName && !(elem.tagName.toLowerCase() in {input: 1, select: 1, textarea: 1, button: 1})) { + continue; + } else if (elem.type === 'radio') { + if (radios[elem.name]) { + continue; + } + radios[elem.name] = true; + } + + pdForms.removeMessages(elem, false); + } + } + + /** * 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. @@ -626,11 +647,6 @@ Nette.validateControl = function(elem, rules, onlyCheck, value, emptyOptional) { elem = elem.tagName ? elem : elem[0]; // RadioNodeList - // 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 - pdForms.removeMessages(elem, false); - if (! rules) { rules = JSON.parse(elem.getAttribute('data-nette-rules') || '[]'); @@ -658,6 +674,16 @@ }; + Nette.validateForm = function(sender, onlyCheck) { + // Assumes the form is valid, therefore removing all messages except those associated with ajax rules. This + // prevents flashing of messages when the ajax rule is evaluated - ajax rules removes their messages when the + // ajax rule is evaluated. + pdForms.removeFormMessages(sender.form || sender); + + return pdForms.Nette.validateForm(sender, onlyCheck); + } + + /** * As a side effect of live validation, errors are shown directly in validateControl. This method is used only for * focusing the first element with error. From 924e0511d7f36d158284a16a5cfe877a80b42240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radek=20=C5=A0er=C3=BD?= Date: Tue, 13 May 2025 09:08:35 +0200 Subject: [PATCH 2/2] Release 4.2.1 --- package.json | 2 +- src/assets/pdForms.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 764da30..b97d767 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "pd-forms", "title": "pdForms", "description": "Customization of netteForms for use in PeckaDesign.", - "version": "4.2.0", + "version": "4.2.1", "author": "PeckaDesign, s.r.o ", "contributors": [ "Radek Šerý ", diff --git a/src/assets/pdForms.js b/src/assets/pdForms.js index dd88223..ab7d8b2 100644 --- a/src/assets/pdForms.js +++ b/src/assets/pdForms.js @@ -1,7 +1,7 @@ /** * @name pdForms * @author Radek Šerý - * @version 4.2.0 + * @version 4.2.1 * * Features: * - live validation @@ -45,7 +45,7 @@ var pdForms = window.pdForms || {}; - pdForms.version = '4.2.0'; + pdForms.version = '4.2.1'; /**