From e5aed915c38cd54c6972eeee38b1884b1b7f4685 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Fri, 13 Oct 2023 18:44:28 +0200 Subject: [PATCH] netteForms: refactoring --- src/assets/netteForms.js | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/assets/netteForms.js b/src/assets/netteForms.js index b5a29cf76..c91c3cf91 100644 --- a/src/assets/netteForms.js +++ b/src/assets/netteForms.js @@ -138,7 +138,6 @@ * Validates form element against given rules. */ Nette.validateControl = function(elem, rules, onlyCheck, value, emptyOptional) { - var top = !rules; elem = elem.tagName ? elem : elem[0]; // RadioNodeList rules = rules || JSON.parse(elem.getAttribute('data-nette-rules') || '[]'); value = value === undefined ? {value: Nette.getEffectiveValue(elem)} : value; @@ -328,9 +327,8 @@ dialog.setAttribute('class', 'netteFormsModal'); dialog.innerText = message + '\n\n'; - dialog.appendChild(style); - dialog.appendChild(button); - document.body.appendChild(dialog); + dialog.append(style, button); + document.body.append(dialog); dialog.showModal(); }; @@ -369,7 +367,7 @@ filled: function(elem, arg, val) { return val !== '' && val !== false && val !== null && (!Array.isArray(val) || !!val.length) - && (!window.FileList || !(val instanceof window.FileList) || val.length); + && (!(val instanceof FileList) || val.length); }, blank: function(elem, arg, val) { @@ -458,7 +456,7 @@ regExp = new RegExp('^(?:' + arg + ')$', caseInsensitive ? 'i' : ''); } - if (window.FileList && val instanceof FileList) { + if (val instanceof FileList) { for (var i = 0; i < val.length; i++) { if (!regExp.test(val[i].name)) { return false; @@ -511,11 +509,9 @@ }, fileSize: function(elem, arg, val) { - if (window.FileList) { - for (var i = 0; i < val.length; i++) { - if (val[i].size > arg) { - return false; - } + for (var i = 0; i < val.length; i++) { + if (val[i].size > arg) { + return false; } } return true; @@ -528,7 +524,7 @@ } re = new RegExp(re.join('|')); - if (window.FileList && val instanceof FileList) { + if (val instanceof FileList) { for (i = 0; i < val.length; i++) { if (val[i].type && !re.test(val[i].type)) { return false; @@ -682,7 +678,7 @@ elem = document.createElement('input'); elem.setAttribute('name', name); elem.setAttribute('type', 'hidden'); - form.appendChild(elem); + form.append(elem); } form.elements[name].value = values[name].join(','); form.elements[name].disabled = values[name].length === 0;