Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 29, 2023
1 parent 3fc301b commit 3c67b8d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 40 deletions.
41 changes: 24 additions & 17 deletions js/3/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 @@ -494,28 +492,37 @@
},

min: function(elem, arg, val) {
return arg === null || parseFloat(val) >= arg;
if (Number.isFinite(arg)) {
val = parseFloat(val);
}
return val >= arg;
},

max: function(elem, arg, val) {
return arg === null || parseFloat(val) <= arg;
if (Number.isFinite(arg)) {
val = parseFloat(val);
}
return val <= arg;
},

range: function(elem, arg, val) {
return Array.isArray(arg) ?
((arg[0] === null || parseFloat(val) >= arg[0]) && (arg[1] === null || parseFloat(val) <= arg[1])) : null;
if (!Array.isArray(arg)) {
return null;
} else if (elem.type === 'time' && arg[0] > arg[1]) {
return val >= arg[0] || val <= arg[1];
}
return (arg[0] === null || Nette.validators.min(elem, arg[0], val))
&& (arg[1] === null || Nette.validators.max(elem, arg[1], val));
},

submitted: function(elem) {
return elem.form['nette-submittedBy'] === elem;
},

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 +535,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 +689,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
Loading

0 comments on commit 3c67b8d

Please sign in to comment.