Skip to content

Commit

Permalink
netteForms: refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Nov 1, 2023
1 parent 6febb11 commit e5aed91
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/assets/netteForms.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
};

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e5aed91

Please sign in to comment.