Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nette-forms

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nette-forms - npm Package Compare versions

Comparing version 2.4.2 to 2.4.9

7

package.json
{
"name": "nette-forms",
"version": "2.4.2",
"version": "2.4.9",
"description": "Client side script for Nette Forms Component",
"keywords": [
"nette",
"validation",
"forms"
],
"homepage": "https://nette.org",

@@ -6,0 +11,0 @@ "author": "David Grudl (https://davidgrudl.com)",

19

readme.md

@@ -19,6 +19,11 @@ Nette Forms: greatly facilitates web forms

Nette Framework puts a great effort to be safe and since forms are the most common user input, Nette forms are as good as impenetrable. All is maintained dynamically and transparently, nothing has to be set manually. Well known vulnerabilities such as Cross Site Scripting (XSS) and Cross-Site Request Forgery (CSRF) are filtered, as well as special control characters. All inputs are checked for UTF-8 validity. Every multiple-choice, select box and similar are checked for forged values upon validating. Sounds good? Let's try it out.
Nette Framework puts a great effort to be safe and since forms are the most common user input, Nette forms are as good as impenetrable. All is maintained dynamically and transparently, nothing has to be set manually. Well-known vulnerabilities such as Cross Site Scripting (XSS) and Cross-Site Request Forgery (CSRF) are filtered, as well as special control characters. All inputs are checked for UTF-8 validity. Every multiple-choice, select boxes and similar are checked for forged values upon validating. Sounds good? Let's try it out.
[See documentation](https://doc.nette.org/en/forms).
Documentation
-------------
This is just a piece of documentation. [Please see our website](https://doc.nette.org/forms).
First form

@@ -40,4 +45,6 @@ ----------

```
Though we mentioned validation, yet our form has none. Let's fix it. We require users to tell us their name, so we should call a `setRequired()` method, which optional argument is an error message to show, if user does not fill his name in:
Although we mentioned validation, our form has none. Let's fix it. In order to require user's name, call `setRequired()` method on the form item. You can pass an error message as optional argument and it will be displayed if user does not fill his name in:
```php

@@ -48,4 +55,6 @@ $form->addText('name', 'Name:')

Try submitting a form without the name - you will keep seeing this message until you meet the validation rules. All that is left for us is setting up JavaScript rules. Luckily it's a piece of cake. We only have to link `netteForms.js`, which is located at `/client-side/forms` in the distribution package.
Try submitting a form without the name - the message is displayed unless you meet the validation rules.
The form is validated on both the client and server side. You only need to link `netteForms.js`, which is located at `/src/assets` in the distribution package.
```html

@@ -63,2 +72,2 @@ <script src="netteForms.js"></script>

[Continue…](https://doc.nette.org/en/forms).
[Continue…](https://doc.nette.org/forms).

@@ -29,708 +29,744 @@ /**

'use strict';
'use strict';
var Nette = {};
var Nette = {};
Nette.formErrors = [];
Nette.version = '2.4';
Nette.formErrors = [];
Nette.version = '2.4';
/**
* Attaches a handler to an event for the element.
*/
Nette.addEvent = function(element, on, callback) {
if (element.addEventListener) {
element.addEventListener(on, callback);
} else if (on === 'DOMContentLoaded') {
element.attachEvent('onreadystatechange', function() {
if (element.readyState === 'complete') {
callback.call(this);
}
});
} else {
element.attachEvent('on' + on, getHandler(callback));
}
};
/**
* Attaches a handler to an event for the element.
*/
Nette.addEvent = function(element, on, callback) {
if (on === 'DOMContentLoaded' && element.readyState !== 'loading') {
callback.call(this);
} else if (element.addEventListener) {
element.addEventListener(on, callback);
} else if (on === 'DOMContentLoaded') {
element.attachEvent('onreadystatechange', function() {
if (element.readyState === 'complete') {
callback.call(this);
}
});
} else {
element.attachEvent('on' + on, getHandler(callback));
}
};
function getHandler(callback) {
return function(e) {
return callback.call(this, e);
};
}
function getHandler(callback) {
return function(e) {
return callback.call(this, e);
};
}
/**
* Returns the value of form element.
*/
Nette.getValue = function(elem) {
var i;
if (!elem) {
return null;
/**
* Returns the value of form element.
*/
Nette.getValue = function(elem) {
var i;
if (!elem) {
return null;
} else if (!elem.tagName) { // RadioNodeList, HTMLCollection, array
return elem[0] ? Nette.getValue(elem[0]) : null;
} else if (!elem.tagName) { // RadioNodeList, HTMLCollection, array
return elem[0] ? Nette.getValue(elem[0]) : null;
} else if (elem.type === 'radio') {
var elements = elem.form.elements; // prevents problem with name 'item' or 'namedItem'
for (i = 0; i < elements.length; i++) {
if (elements[i].name === elem.name && elements[i].checked) {
return elements[i].value;
} else if (elem.type === 'radio') {
var elements = elem.form.elements; // prevents problem with name 'item' or 'namedItem'
for (i = 0; i < elements.length; i++) {
if (elements[i].name === elem.name && elements[i].checked) {
return elements[i].value;
}
}
}
return null;
return null;
} else if (elem.type === 'file') {
return elem.files || elem.value;
} else if (elem.type === 'file') {
return elem.files || elem.value;
} else if (elem.tagName.toLowerCase() === 'select') {
var index = elem.selectedIndex,
options = elem.options,
values = [];
} else if (elem.tagName.toLowerCase() === 'select') {
var index = elem.selectedIndex,
options = elem.options,
values = [];
if (elem.type === 'select-one') {
return index < 0 ? null : options[index].value;
}
if (elem.type === 'select-one') {
return index < 0 ? null : options[index].value;
}
for (i = 0; i < options.length; i++) {
if (options[i].selected) {
values.push(options[i].value);
for (i = 0; i < options.length; i++) {
if (options[i].selected) {
values.push(options[i].value);
}
}
}
return values;
return values;
} else if (elem.name && elem.name.match(/\[\]$/)) { // multiple elements []
var elements = elem.form.elements[elem.name].tagName ? [elem] : elem.form.elements[elem.name],
} else if (elem.name && elem.name.match(/\[\]$/)) { // multiple elements []
elements = elem.form.elements[elem.name].tagName ? [elem] : elem.form.elements[elem.name];
values = [];
for (i = 0; i < elements.length; i++) {
if (elements[i].type !== 'checkbox' || elements[i].checked) {
values.push(elements[i].value);
for (i = 0; i < elements.length; i++) {
if (elements[i].type !== 'checkbox' || elements[i].checked) {
values.push(elements[i].value);
}
}
}
return values;
return values;
} else if (elem.type === 'checkbox') {
return elem.checked;
} else if (elem.type === 'checkbox') {
return elem.checked;
} else if (elem.tagName.toLowerCase() === 'textarea') {
return elem.value.replace("\r", '');
} else if (elem.tagName.toLowerCase() === 'textarea') {
return elem.value.replace('\r', '');
} else {
return elem.value.replace("\r", '').replace(/^\s+|\s+$/g, '');
}
};
} else {
return elem.value.replace('\r', '').replace(/^\s+|\s+$/g, '');
}
};
/**
* Returns the effective value of form element.
*/
Nette.getEffectiveValue = function(elem) {
var val = Nette.getValue(elem);
if (elem.getAttribute) {
if (val === elem.getAttribute('data-nette-empty-value')) {
val = '';
/**
* Returns the effective value of form element.
*/
Nette.getEffectiveValue = function(elem) {
var val = Nette.getValue(elem);
if (elem.getAttribute) {
if (val === elem.getAttribute('data-nette-empty-value')) {
val = '';
}
}
}
return val;
};
return val;
};
/**
* Validates form element against given rules.
*/
Nette.validateControl = function(elem, rules, onlyCheck, value, emptyOptional) {
elem = elem.tagName ? elem : elem[0]; // RadioNodeList
rules = rules || Nette.parseJSON(elem.getAttribute('data-nette-rules'));
value = value === undefined ? {value: Nette.getEffectiveValue(elem)} : value;
/**
* Validates form element against given rules.
*/
Nette.validateControl = function(elem, rules, onlyCheck, value, emptyOptional) {
elem = elem.tagName ? elem : elem[0]; // RadioNodeList
rules = rules || Nette.parseJSON(elem.getAttribute('data-nette-rules'));
value = value === undefined ? {value: Nette.getEffectiveValue(elem)} : value;
for (var id = 0, len = rules.length; id < len; id++) {
var rule = rules[id],
op = rule.op.match(/(~)?([^?]+)/),
curElem = rule.control ? elem.form.elements.namedItem(rule.control) : elem;
for (var id = 0, len = rules.length; id < len; id++) {
var rule = rules[id],
op = rule.op.match(/(~)?([^?]+)/),
curElem = rule.control ? elem.form.elements.namedItem(rule.control) : elem;
rule.neg = op[1];
rule.op = op[2];
rule.condition = !!rule.rules;
rule.neg = op[1];
rule.op = op[2];
rule.condition = !!rule.rules;
if (!curElem) {
continue;
} else if (rule.op === 'optional') {
emptyOptional = !Nette.validateRule(elem, ':filled', null, value);
continue;
} else if (emptyOptional && !rule.condition && rule.op !== ':filled') {
continue;
}
if (!curElem) {
continue;
} else if (rule.op === 'optional') {
emptyOptional = !Nette.validateRule(elem, ':filled', null, value);
continue;
} else if (emptyOptional && !rule.condition && rule.op !== ':filled') {
continue;
}
curElem = curElem.tagName ? curElem : curElem[0]; // RadioNodeList
var curValue = elem === curElem ? value : {value: Nette.getEffectiveValue(curElem)},
success = Nette.validateRule(curElem, rule.op, rule.arg, curValue);
curElem = curElem.tagName ? curElem : curElem[0]; // RadioNodeList
var curValue = elem === curElem ? value : {value: Nette.getEffectiveValue(curElem)},
success = Nette.validateRule(curElem, rule.op, rule.arg, curValue);
if (success === null) {
continue;
} else if (rule.neg) {
success = !success;
}
if (success === null) {
continue;
} else if (rule.neg) {
success = !success;
}
if (rule.condition && success) {
if (!Nette.validateControl(elem, rule.rules, onlyCheck, value, rule.op === ':blank' ? false : emptyOptional)) {
if (rule.condition && success) {
if (!Nette.validateControl(elem, rule.rules, onlyCheck, value, rule.op === ':blank' ? false : emptyOptional)) {
return false;
}
} else if (!rule.condition && !success) {
if (Nette.isDisabled(curElem)) {
continue;
}
if (!onlyCheck) {
var arr = Nette.isArray(rule.arg) ? rule.arg : [rule.arg],
message = rule.msg.replace(/%(value|\d+)/g, function(foo, m) {
return Nette.getValue(m === 'value' ? curElem : elem.form.elements.namedItem(arr[m].control));
});
Nette.addError(curElem, message);
}
return false;
}
} else if (!rule.condition && !success) {
if (Nette.isDisabled(curElem)) {
continue;
}
}
if (elem.type === 'number' && !elem.validity.valid) {
if (!onlyCheck) {
var arr = Nette.isArray(rule.arg) ? rule.arg : [rule.arg],
message = rule.msg.replace(/%(value|\d+)/g, function(foo, m) {
return Nette.getValue(m === 'value' ? curElem : elem.form.elements.namedItem(arr[m].control));
});
Nette.addError(curElem, message);
Nette.addError(elem, 'Please enter a valid value.');
}
return false;
}
}
if (elem.type === 'number' && !elem.validity.valid) {
if (!onlyCheck) {
Nette.addError(elem, 'Please enter a valid value.');
}
return false;
}
return true;
};
return true;
};
/**
* Validates whole form.
*/
Nette.validateForm = function(sender, onlyCheck) {
var form = sender.form || sender,
scope = false;
/**
* Validates whole form.
*/
Nette.validateForm = function(sender, onlyCheck) {
var form = sender.form || sender,
scope = false;
Nette.formErrors = [];
Nette.formErrors = [];
if (form['nette-submittedBy'] && form['nette-submittedBy'].getAttribute('formnovalidate') !== null) {
var scopeArr = Nette.parseJSON(form['nette-submittedBy'].getAttribute('data-nette-validation-scope'));
if (scopeArr.length) {
scope = new RegExp('^(' + scopeArr.join('-|') + '-)');
} else {
Nette.showFormErrors(form, []);
return true;
if (form['nette-submittedBy'] && form['nette-submittedBy'].getAttribute('formnovalidate') !== null) {
var scopeArr = Nette.parseJSON(form['nette-submittedBy'].getAttribute('data-nette-validation-scope'));
if (scopeArr.length) {
scope = new RegExp('^(' + scopeArr.join('-|') + '-)');
} else {
Nette.showFormErrors(form, []);
return true;
}
}
}
var radios = {}, i, elem;
var radios = {}, i, elem;
for (i = 0; i < form.elements.length; i++) {
elem = form.elements[i];
for (i = 0; i < form.elements.length; i++) {
elem = form.elements[i];
if (elem.tagName && !(elem.tagName.toLowerCase() in {input: 1, select: 1, textarea: 1, button: 1})) {
continue;
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]) {
} else if (elem.type === 'radio') {
if (radios[elem.name]) {
continue;
}
radios[elem.name] = true;
}
if ((scope && !elem.name.replace(/]\[|\[|]|$/g, '-').match(scope)) || Nette.isDisabled(elem)) {
continue;
}
radios[elem.name] = true;
}
if ((scope && !elem.name.replace(/]\[|\[|]|$/g, '-').match(scope)) || Nette.isDisabled(elem)) {
continue;
if (!Nette.validateControl(elem, null, onlyCheck) && !Nette.formErrors.length) {
return false;
}
}
var success = !Nette.formErrors.length;
Nette.showFormErrors(form, Nette.formErrors);
return success;
};
if (!Nette.validateControl(elem, null, onlyCheck) && !Nette.formErrors.length) {
return false;
}
}
var success = !Nette.formErrors.length;
Nette.showFormErrors(form, Nette.formErrors);
return success;
};
/**
* Check if input is disabled.
*/
Nette.isDisabled = function(elem) {
if (elem.type === 'radio') {
for (var i = 0, elements = elem.form.elements; i < elements.length; i++) {
if (elements[i].name === elem.name && !elements[i].disabled) {
return false;
/**
* Check if input is disabled.
*/
Nette.isDisabled = function(elem) {
if (elem.type === 'radio') {
for (var i = 0, elements = elem.form.elements; i < elements.length; i++) {
if (elements[i].name === elem.name && !elements[i].disabled) {
return false;
}
}
return true;
}
return true;
}
return elem.disabled;
};
return elem.disabled;
};
/**
* Adds error message to the queue.
*/
Nette.addError = function(elem, message) {
Nette.formErrors.push({
element: elem,
message: message
});
};
/**
* Adds error message to the queue.
*/
Nette.addError = function(elem, message) {
Nette.formErrors.push({
element: elem,
message: message
});
};
/**
* Display error messages.
*/
Nette.showFormErrors = function(form, errors) {
var messages = [],
focusElem;
/**
* Display error messages.
*/
Nette.showFormErrors = function(form, errors) {
var messages = [],
focusElem;
for (var i = 0; i < errors.length; i++) {
var elem = errors[i].element,
message = errors[i].message;
for (var i = 0; i < errors.length; i++) {
var elem = errors[i].element,
message = errors[i].message;
if (!Nette.inArray(messages, message)) {
messages.push(message);
if (!Nette.inArray(messages, message)) {
messages.push(message);
if (!focusElem && elem.focus) {
focusElem = elem;
if (!focusElem && elem.focus) {
focusElem = elem;
}
}
}
}
if (messages.length) {
alert(messages.join('\n'));
if (messages.length) {
alert(messages.join('\n'));
if (focusElem) {
focusElem.focus();
if (focusElem) {
focusElem.focus();
}
}
}
};
};
/**
* Expand rule argument.
*/
Nette.expandRuleArgument = function(form, arg) {
if (arg && arg.control) {
var control = form.elements.namedItem(arg.control),
value = {value: Nette.getEffectiveValue(control)};
Nette.validateControl(control, null, true, value);
arg = value.value;
}
return arg;
};
/**
* Expand rule argument.
*/
Nette.expandRuleArgument = function(form, arg) {
if (arg && arg.control) {
var control = form.elements.namedItem(arg.control),
value = {value: Nette.getEffectiveValue(control)};
Nette.validateControl(control, null, true, value);
arg = value.value;
}
return arg;
};
/**
* Validates single rule.
*/
Nette.validateRule = function(elem, op, arg, value) {
value = value === undefined ? {value: Nette.getEffectiveValue(elem)} : value;
var preventFiltering = false;
if (op.charAt(0) === ':') {
op = op.substr(1);
}
op = op.replace('::', '_');
op = op.replace(/\\/g, '');
/**
* Validates single rule.
*/
Nette.validateRule = function(elem, op, arg, value) {
value = value === undefined ? {value: Nette.getEffectiveValue(elem)} : value;
var arr = Nette.isArray(arg) ? arg.slice(0) : [arg];
for (var i = 0, len = arr.length; i < len; i++) {
arr[i] = Nette.expandRuleArgument(elem.form, arr[i]);
}
return Nette.validators[op]
? Nette.validators[op](elem, Nette.isArray(arg) ? arr : arr[0], value.value, value)
: null;
};
if (op.charAt(0) === ':') {
op = op.substr(1);
}
op = op.replace('::', '_');
op = op.replace(/\\/g, '');
Nette.validators = {
filled: function(elem, arg, val) {
if (elem.type === 'number' && elem.validity.badInput) {
return true;
var arr = Nette.isArray(arg) ? arg.slice(0) : [arg];
if (!preventFiltering) {
preventFiltering = true;
for (var i = 0, len = arr.length; i < len; i++) {
arr[i] = Nette.expandRuleArgument(elem.form, arr[i]);
}
preventFiltering = false;
}
return val !== '' && val !== false && val !== null
&& (!Nette.isArray(val) || !!val.length)
&& (!window.FileList || !(val instanceof window.FileList) || val.length);
},
return Nette.validators[op]
? Nette.validators[op](elem, Nette.isArray(arg) ? arr : arr[0], value.value, value)
: null;
};
blank: function(elem, arg, val) {
return !Nette.validators.filled(elem, arg, val);
},
valid: function(elem, arg, val) {
return Nette.validateControl(elem, null, true);
},
Nette.validators = {
filled: function(elem, arg, val) {
if (elem.type === 'number' && elem.validity.badInput) {
return true;
}
return val !== '' && val !== false && val !== null
&& (!Nette.isArray(val) || !!val.length)
&& (!window.FileList || !(val instanceof window.FileList) || val.length);
},
equal: function(elem, arg, val) {
if (arg === undefined) {
return null;
}
blank: function(elem, arg, val) {
return !Nette.validators.filled(elem, arg, val);
},
function toString(val) {
if (typeof val === 'number' || typeof val === 'string') {
return '' + val;
} else {
return val === true ? '1' : '';
valid: function(elem) {
return Nette.validateControl(elem, null, true);
},
equal: function(elem, arg, val) {
if (arg === undefined) {
return null;
}
}
val = Nette.isArray(val) ? val : [val];
arg = Nette.isArray(arg) ? arg : [arg];
loop:
for (var i1 = 0, len1 = val.length; i1 < len1; i1++) {
for (var i2 = 0, len2 = arg.length; i2 < len2; i2++) {
if (toString(val[i1]) === toString(arg[i2])) {
continue loop;
function toString(val) {
if (typeof val === 'number' || typeof val === 'string') {
return '' + val;
} else {
return val === true ? '1' : '';
}
}
return false;
}
return true;
},
notEqual: function(elem, arg, val) {
return arg === undefined ? null : !Nette.validators.equal(elem, arg, val);
},
val = Nette.isArray(val) ? val : [val];
arg = Nette.isArray(arg) ? arg : [arg];
loop:
for (var i1 = 0, len1 = val.length; i1 < len1; i1++) {
for (var i2 = 0, len2 = arg.length; i2 < len2; i2++) {
if (toString(val[i1]) === toString(arg[i2])) {
continue loop;
}
}
return false;
}
return true;
},
minLength: function(elem, arg, val) {
if (elem.type === 'number') {
if (elem.validity.tooShort) {
return false
} else if (elem.validity.badInput) {
return null;
notEqual: function(elem, arg, val) {
return arg === undefined ? null : !Nette.validators.equal(elem, arg, val);
},
minLength: function(elem, arg, val) {
if (elem.type === 'number') {
if (elem.validity.tooShort) {
return false;
} else if (elem.validity.badInput) {
return null;
}
}
}
return val.length >= arg;
},
return val.length >= arg;
},
maxLength: function(elem, arg, val) {
if (elem.type === 'number') {
if (elem.validity.tooLong) {
return false
} else if (elem.validity.badInput) {
return null;
maxLength: function(elem, arg, val) {
if (elem.type === 'number') {
if (elem.validity.tooLong) {
return false;
} else if (elem.validity.badInput) {
return null;
}
}
}
return val.length <= arg;
},
return val.length <= arg;
},
length: function(elem, arg, val) {
if (elem.type === 'number') {
if (elem.validity.tooShort || elem.validity.tooLong) {
return false
} else if (elem.validity.badInput) {
length: function(elem, arg, val) {
if (elem.type === 'number') {
if (elem.validity.tooShort || elem.validity.tooLong) {
return false;
} else if (elem.validity.badInput) {
return null;
}
}
arg = Nette.isArray(arg) ? arg : [arg, arg];
return (arg[0] === null || val.length >= arg[0]) && (arg[1] === null || val.length <= arg[1]);
},
email: function(elem, arg, val) {
return (/^("([ !#-[\]-~]|\\[ -~])+"|[-a-z0-9!#$%&'*+/=?^_`{|}~]+(\.[-a-z0-9!#$%&'*+/=?^_`{|}~]+)*)@([0-9a-z\u00C0-\u02FF\u0370-\u1EFF]([-0-9a-z\u00C0-\u02FF\u0370-\u1EFF]{0,61}[0-9a-z\u00C0-\u02FF\u0370-\u1EFF])?\.)+[a-z\u00C0-\u02FF\u0370-\u1EFF]([-0-9a-z\u00C0-\u02FF\u0370-\u1EFF]{0,17}[a-z\u00C0-\u02FF\u0370-\u1EFF])?$/i).test(val);
},
url: function(elem, arg, val, value) {
if (!(/^[a-z\d+.-]+:/).test(val)) {
val = 'http://' + val;
}
if ((/^https?:\/\/((([-_0-9a-z\u00C0-\u02FF\u0370-\u1EFF]+\.)*[0-9a-z\u00C0-\u02FF\u0370-\u1EFF]([-0-9a-z\u00C0-\u02FF\u0370-\u1EFF]{0,61}[0-9a-z\u00C0-\u02FF\u0370-\u1EFF])?\.)?[a-z\u00C0-\u02FF\u0370-\u1EFF]([-0-9a-z\u00C0-\u02FF\u0370-\u1EFF]{0,17}[a-z\u00C0-\u02FF\u0370-\u1EFF])?|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|\[[0-9a-f:]{3,39}\])(:\d{1,5})?(\/\S*)?$/i).test(val)) {
value.value = val;
return true;
}
return false;
},
regexp: function(elem, arg, val) {
var parts = typeof arg === 'string' ? arg.match(/^\/(.*)\/([imu]*)$/) : false;
try {
return parts && (new RegExp(parts[1], parts[2].replace('u', ''))).test(val);
} catch (e) {} // eslint-disable-line no-empty
},
pattern: function(elem, arg, val, value, caseInsensitive) {
if (typeof arg !== 'string') {
return null;
}
}
arg = Nette.isArray(arg) ? arg : [arg, arg];
return (arg[0] === null || val.length >= arg[0]) && (arg[1] === null || val.length <= arg[1]);
},
email: function(elem, arg, val) {
return (/^("([ !#-[\]-~]|\\[ -~])+"|[-a-z0-9!#$%&'*+\/=?^_`{|}~]+(\.[-a-z0-9!#$%&'*+\/=?^_`{|}~]+)*)@([0-9a-z\u00C0-\u02FF\u0370-\u1EFF]([-0-9a-z\u00C0-\u02FF\u0370-\u1EFF]{0,61}[0-9a-z\u00C0-\u02FF\u0370-\u1EFF])?\.)+[a-z\u00C0-\u02FF\u0370-\u1EFF]([-0-9a-z\u00C0-\u02FF\u0370-\u1EFF]{0,17}[a-z\u00C0-\u02FF\u0370-\u1EFF])?$/i).test(val);
},
try {
try {
var regExp = new RegExp('^(?:' + arg + ')$', caseInsensitive ? 'ui' : 'u');
} catch (e) {
regExp = new RegExp('^(?:' + arg + ')$', caseInsensitive ? 'i' : '');
}
url: function(elem, arg, val, value) {
if (!(/^[a-z\d+.-]+:/).test(val)) {
val = 'http://' + val;
}
if ((/^https?:\/\/((([-_0-9a-z\u00C0-\u02FF\u0370-\u1EFF]+\.)*[0-9a-z\u00C0-\u02FF\u0370-\u1EFF]([-0-9a-z\u00C0-\u02FF\u0370-\u1EFF]{0,61}[0-9a-z\u00C0-\u02FF\u0370-\u1EFF])?\.)?[a-z\u00C0-\u02FF\u0370-\u1EFF]([-0-9a-z\u00C0-\u02FF\u0370-\u1EFF]{0,17}[a-z\u00C0-\u02FF\u0370-\u1EFF])?|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|\[[0-9a-f:]{3,39}\])(:\d{1,5})?(\/\S*)?$/i).test(val)) {
value.value = val;
return true;
}
return false;
},
if (window.FileList && val instanceof FileList) {
for (var i = 0; i < val.length; i++) {
if (!regExp.test(val[i].name)) {
return false;
}
}
regexp: function(elem, arg, val) {
var parts = typeof arg === 'string' ? arg.match(/^\/(.*)\/([imu]*)$/) : false;
try {
return parts && (new RegExp(parts[1], parts[2].replace('u', ''))).test(val);
} catch (e) {}
},
return true;
}
pattern: function(elem, arg, val) {
try {
return typeof arg === 'string' ? (new RegExp('^(?:' + arg + ')$')).test(val) : null;
} catch (e) {}
},
return regExp.test(val);
} catch (e) {} // eslint-disable-line no-empty
},
integer: function(elem, arg, val) {
if (elem.type === 'number' && elem.validity.badInput) {
return false;
}
return (/^-?[0-9]+$/).test(val);
},
patternCaseInsensitive: function(elem, arg, val) {
return Nette.validators.pattern(elem, arg, val, null, true);
},
'float': function(elem, arg, val, value) {
if (elem.type === 'number' && elem.validity.badInput) {
integer: function(elem, arg, val) {
if (elem.type === 'number' && elem.validity.badInput) {
return false;
}
return (/^-?[0-9]+$/).test(val);
},
'float': function(elem, arg, val, value) {
if (elem.type === 'number' && elem.validity.badInput) {
return false;
}
val = val.replace(/ +/g, '').replace(/,/g, '.');
if ((/^-?[0-9]*\.?[0-9]+$/).test(val)) {
value.value = val;
return true;
}
return false;
}
val = val.replace(' ', '').replace(',', '.');
if ((/^-?[0-9]*[.,]?[0-9]+$/).test(val)) {
value.value = val;
return true;
}
return false;
},
},
min: function(elem, arg, val) {
if (elem.type === 'number') {
if (elem.validity.rangeUnderflow) {
return false
} else if (elem.validity.badInput) {
return null;
min: function(elem, arg, val) {
if (elem.type === 'number') {
if (elem.validity.rangeUnderflow) {
return false;
} else if (elem.validity.badInput) {
return null;
}
}
}
return arg === null || parseFloat(val) >= arg;
},
return arg === null || parseFloat(val) >= arg;
},
max: function(elem, arg, val) {
if (elem.type === 'number') {
if (elem.validity.rangeOverflow) {
return false
} else if (elem.validity.badInput) {
return null;
max: function(elem, arg, val) {
if (elem.type === 'number') {
if (elem.validity.rangeOverflow) {
return false;
} else if (elem.validity.badInput) {
return null;
}
}
}
return arg === null || parseFloat(val) <= arg;
},
return arg === null || parseFloat(val) <= arg;
},
range: function(elem, arg, val) {
if (elem.type === 'number') {
if (elem.validity.rangeUnderflow || elem.validity.rangeOverflow) {
return false
} else if (elem.validity.badInput) {
return null;
range: function(elem, arg, val) {
if (elem.type === 'number') {
if (elem.validity.rangeUnderflow || elem.validity.rangeOverflow) {
return false;
} else if (elem.validity.badInput) {
return null;
}
}
}
return Nette.isArray(arg) ?
((arg[0] === null || parseFloat(val) >= arg[0]) && (arg[1] === null || parseFloat(val) <= arg[1])) : null;
},
return Nette.isArray(arg) ?
((arg[0] === null || parseFloat(val) >= arg[0]) && (arg[1] === null || parseFloat(val) <= arg[1])) : null;
},
submitted: function(elem, arg, val) {
return elem.form['nette-submittedBy'] === elem;
},
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;
fileSize: function(elem, arg, val) {
if (window.FileList) {
for (var i = 0; i < val.length; i++) {
if (val[i].size > arg) {
return false;
}
}
}
}
return true;
},
return true;
},
image: function (elem, arg, val) {
if (window.FileList && val instanceof window.FileList) {
for (var i = 0; i < val.length; i++) {
var type = val[i].type;
if (type && type !== 'image/gif' && type !== 'image/png' && type !== 'image/jpeg') {
return false;
image: function (elem, arg, val) {
if (window.FileList && val instanceof window.FileList) {
for (var i = 0; i < val.length; i++) {
var type = val[i].type;
if (type && type !== 'image/gif' && type !== 'image/png' && type !== 'image/jpeg') {
return false;
}
}
}
return true;
},
'static': function (elem, arg) {
return arg;
}
return true;
}
};
};
/**
* Process all toggles in form.
*/
Nette.toggleForm = function(form, elem) {
var i;
Nette.toggles = {};
for (i = 0; i < form.elements.length; i++) {
if (form.elements[i].tagName.toLowerCase() in {input: 1, select: 1, textarea: 1, button: 1}) {
Nette.toggleControl(form.elements[i], null, null, !elem);
/**
* Process all toggles in form.
*/
Nette.toggleForm = function(form, elem) {
var i;
Nette.toggles = {};
for (i = 0; i < form.elements.length; i++) {
if (form.elements[i].tagName.toLowerCase() in {input: 1, select: 1, textarea: 1, button: 1}) {
Nette.toggleControl(form.elements[i], null, null, !elem);
}
}
}
for (i in Nette.toggles) {
Nette.toggle(i, Nette.toggles[i], elem);
}
};
for (i in Nette.toggles) {
Nette.toggle(i, Nette.toggles[i], elem);
}
};
/**
* Process toggles on form element.
*/
Nette.toggleControl = function(elem, rules, success, firsttime, value) {
rules = rules || Nette.parseJSON(elem.getAttribute('data-nette-rules'));
value = value === undefined ? {value: Nette.getEffectiveValue(elem)} : value;
/**
* Process toggles on form element.
*/
Nette.toggleControl = function(elem, rules, success, firsttime, value) {
rules = rules || Nette.parseJSON(elem.getAttribute('data-nette-rules'));
value = value === undefined ? {value: Nette.getEffectiveValue(elem)} : value;
var has = false,
handled = [],
handler = function () {
Nette.toggleForm(elem.form, elem);
},
curSuccess;
var has = false,
handled = [],
handler = function () {
Nette.toggleForm(elem.form, elem);
},
curSuccess;
for (var id = 0, len = rules.length; id < len; id++) {
var rule = rules[id],
op = rule.op.match(/(~)?([^?]+)/),
curElem = rule.control ? elem.form.elements.namedItem(rule.control) : elem;
for (var id = 0, len = rules.length; id < len; id++) {
var rule = rules[id],
op = rule.op.match(/(~)?([^?]+)/),
curElem = rule.control ? elem.form.elements.namedItem(rule.control) : elem;
if (!curElem) {
continue;
}
curSuccess = success;
if (success !== false) {
rule.neg = op[1];
rule.op = op[2];
var curValue = elem === curElem ? value : {value: Nette.getEffectiveValue(curElem)};
curSuccess = Nette.validateRule(curElem, rule.op, rule.arg, curValue);
if (curSuccess === null) {
if (!curElem) {
continue;
}
} else if (rule.neg) {
curSuccess = !curSuccess;
curSuccess = success;
if (success !== false) {
rule.neg = op[1];
rule.op = op[2];
var curValue = elem === curElem ? value : {value: Nette.getEffectiveValue(curElem)};
curSuccess = Nette.validateRule(curElem, rule.op, rule.arg, curValue);
if (curSuccess === null) {
continue;
} else if (rule.neg) {
curSuccess = !curSuccess;
}
if (!rule.rules) {
success = curSuccess;
}
}
if (!rule.rules) {
success = curSuccess;
}
}
if ((rule.rules && Nette.toggleControl(elem, rule.rules, curSuccess, firsttime, value)) || rule.toggle) {
has = true;
if (firsttime) {
var oldIE = !document.addEventListener, // IE < 9
name = curElem.tagName ? curElem.name : curElem[0].name,
els = curElem.tagName ? curElem.form.elements : curElem;
if ((rule.rules && Nette.toggleControl(elem, rule.rules, curSuccess, firsttime, value)) || rule.toggle) {
has = true;
if (firsttime) {
var oldIE = !document.addEventListener, // IE < 9
name = curElem.tagName ? curElem.name : curElem[0].name,
els = curElem.tagName ? curElem.form.elements : curElem;
for (var i = 0; i < els.length; i++) {
if (els[i].name === name && !Nette.inArray(handled, els[i])) {
Nette.addEvent(els[i], oldIE && els[i].type in {checkbox: 1, radio: 1} ? 'click' : 'change', handler);
handled.push(els[i]);
for (var i = 0; i < els.length; i++) {
if (els[i].name === name && !Nette.inArray(handled, els[i])) {
Nette.addEvent(els[i], oldIE && els[i].type in {checkbox: 1, radio: 1} ? 'click' : 'change', handler);
handled.push(els[i]);
}
}
}
}
for (var id2 in rule.toggle || []) {
if (Object.prototype.hasOwnProperty.call(rule.toggle, id2)) {
Nette.toggles[id2] = Nette.toggles[id2] || (rule.toggle[id2] ? curSuccess : !curSuccess);
for (var id2 in rule.toggle || []) {
if (Object.prototype.hasOwnProperty.call(rule.toggle, id2)) {
Nette.toggles[id2] = Nette.toggles[id2] || (rule.toggle[id2] ? curSuccess : !curSuccess);
}
}
}
}
}
return has;
};
return has;
};
Nette.parseJSON = function(s) {
return (s || '').substr(0, 3) === '{op'
? eval('[' + s + ']') // backward compatibility with Nette 2.0.x
: JSON.parse(s || '[]');
};
Nette.parseJSON = function(s) {
return (s || '').substr(0, 3) === '{op'
? eval('[' + s + ']') // backward compatibility with Nette 2.0.x
: JSON.parse(s || '[]');
};
/**
* Displays or hides HTML element.
*/
Nette.toggle = function(id, visible, srcElement) {
var elem = document.getElementById(id);
if (elem) {
elem.style.display = visible ? '' : 'none';
}
};
/**
* Displays or hides HTML element.
*/
Nette.toggle = function(id, visible, srcElement) { // eslint-disable-line no-unused-vars
var elem = document.getElementById(id);
if (elem) {
elem.style.display = visible ? '' : 'none';
}
};
/**
* Setup handlers.
*/
Nette.initForm = function(form) {
Nette.toggleForm(form);
/**
* Setup handlers.
*/
Nette.initForm = function(form) {
Nette.toggleForm(form);
if (form.noValidate) {
return;
}
if (form.noValidate) {
return;
}
form.noValidate = true;
form.noValidate = true;
Nette.addEvent(form, 'submit', function(e) {
if (!Nette.validateForm(form)) {
if (e && e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
} else if (window.event) {
event.cancelBubble = true;
event.returnValue = false;
Nette.addEvent(form, 'submit', function(e) {
if (!Nette.validateForm(form)) {
if (e && e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
} else if (window.event) {
event.cancelBubble = true;
event.returnValue = false;
}
}
}
});
};
});
};
/**
* @private
*/
Nette.initOnLoad = function() {
Nette.addEvent(document, 'DOMContentLoaded', function() {
for (var i = 0; i < document.forms.length; i++) {
var form = document.forms[i];
for (var j = 0; j < form.elements.length; j++) {
if (form.elements[j].getAttribute('data-nette-rules')) {
Nette.initForm(form);
break;
/**
* @private
*/
Nette.initOnLoad = function() {
Nette.addEvent(document, 'DOMContentLoaded', function() {
for (var i = 0; i < document.forms.length; i++) {
var form = document.forms[i];
for (var j = 0; j < form.elements.length; j++) {
if (form.elements[j].getAttribute('data-nette-rules')) {
Nette.initForm(form);
break;
}
}
}
}
Nette.addEvent(document.body, 'click', function(e) {
var target = e.target || e.srcElement;
while (target) {
if (target.form && target.type in {submit: 1, image: 1}) {
target.form['nette-submittedBy'] = target;
break;
Nette.addEvent(document.body, 'click', function(e) {
var target = e.target || e.srcElement;
while (target) {
if (target.form && target.type in {submit: 1, image: 1}) {
target.form['nette-submittedBy'] = target;
break;
}
target = target.parentNode;
}
target = target.parentNode;
}
});
});
});
};
};
/**
* Determines whether the argument is an array.
*/
Nette.isArray = function(arg) {
return Object.prototype.toString.call(arg) === '[object Array]';
};
/**
* Determines whether the argument is an array.
*/
Nette.isArray = function(arg) {
return Object.prototype.toString.call(arg) === '[object Array]';
};
/**
* Search for a specified value within an array.
*/
Nette.inArray = function(arr, val) {
if ([].indexOf) {
return arr.indexOf(val) > -1;
} else {
for (var i = 0; i < arr.length; i++) {
if (arr[i] === val) {
return true;
/**
* Search for a specified value within an array.
*/
Nette.inArray = function(arr, val) {
if ([].indexOf) {
return arr.indexOf(val) > -1;
} else {
for (var i = 0; i < arr.length; i++) {
if (arr[i] === val) {
return true;
}
}
return false;
}
return false;
}
};
};
/**
* Converts string to web safe characters [a-z0-9-] text.
*/
Nette.webalize = function(s) {
s = s.toLowerCase();
var res = '', i, ch;
for (i = 0; i < s.length; i++) {
ch = Nette.webalizeTable[s.charAt(i)];
res += ch ? ch : s.charAt(i);
}
return res.replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');
};
/**
* Converts string to web safe characters [a-z0-9-] text.
*/
Nette.webalize = function(s) {
s = s.toLowerCase();
var res = '', i, ch;
for (i = 0; i < s.length; i++) {
ch = Nette.webalizeTable[s.charAt(i)];
res += ch ? ch : s.charAt(i);
}
return res.replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');
};
Nette.webalizeTable = {\u00e1: 'a', \u00e4: 'a', \u010d: 'c', \u010f: 'd', \u00e9: 'e', \u011b: 'e', \u00ed: 'i', \u013e: 'l', \u0148: 'n', \u00f3: 'o', \u00f4: 'o', \u0159: 'r', \u0161: 's', \u0165: 't', \u00fa: 'u', \u016f: 'u', \u00fd: 'y', \u017e: 'z'};
Nette.webalizeTable = {\u00e1: 'a', \u00e4: 'a', \u010d: 'c', \u010f: 'd', \u00e9: 'e', \u011b: 'e', \u00ed: 'i', \u013e: 'l', \u0148: 'n', \u00f3: 'o', \u00f4: 'o', \u0159: 'r', \u0161: 's', \u0165: 't', \u00fa: 'u', \u016f: 'u', \u00fd: 'y', \u017e: 'z'};
return Nette;
return Nette;
}));

@@ -1,21 +0,22 @@

/*! netteForms.js | (c) 2004, 2016 David Grudl (http://davidgrudl.com) */
(function(e,p){if(e.JSON)if("function"===typeof define&&define.amd)define(function(){return p(e)});else if("object"===typeof module&&"object"===typeof module.exports)module.exports=p(e);else{var d=!e.Nette||!e.Nette.noInit;e.Nette=p(e);d&&e.Nette.initOnLoad()}})("undefined"!==typeof window?window:this,function(e){function p(a){return function(b){return a.call(this,b)}}var d={formErrors:[],version:"2.4",addEvent:function(a,b,c){a.addEventListener?a.addEventListener(b,c):"DOMContentLoaded"===b?a.attachEvent("onreadystatechange",
function(){"complete"===a.readyState&&c.call(this)}):a.attachEvent("on"+b,p(c))},getValue:function(a){var b;if(a){if(a.tagName){if("radio"===a.type){var c=a.form.elements;for(b=0;b<c.length;b++)if(c[b].name===a.name&&c[b].checked)return c[b].value;return null}if("file"===a.type)return a.files||a.value;if("select"===a.tagName.toLowerCase()){b=a.selectedIndex;var c=a.options,f=[];if("select-one"===a.type)return 0>b?null:c[b].value;for(b=0;b<c.length;b++)c[b].selected&&f.push(c[b].value);return f}if(a.name&&
a.name.match(/\[\]$/)){c=a.form.elements[a.name].tagName?[a]:a.form.elements[a.name];f=[];for(b=0;b<c.length;b++)("checkbox"!==c[b].type||c[b].checked)&&f.push(c[b].value);return f}return"checkbox"===a.type?a.checked:"textarea"===a.tagName.toLowerCase()?a.value.replace("\r",""):a.value.replace("\r","").replace(/^\s+|\s+$/g,"")}return a[0]?d.getValue(a[0]):null}return null},getEffectiveValue:function(a){var b=d.getValue(a);a.getAttribute&&b===a.getAttribute("data-nette-empty-value")&&(b="");return b},
validateControl:function(a,b,c,f,u){a=a.tagName?a:a[0];b=b||d.parseJSON(a.getAttribute("data-nette-rules"));f=void 0===f?{value:d.getEffectiveValue(a)}:f;for(var g=0,l=b.length;g<l;g++){var h=b[g],k=h.op.match(/(~)?([^?]+)/),e=h.control?a.form.elements.namedItem(h.control):a;h.neg=k[1];h.op=k[2];h.condition=!!h.rules;if(e)if("optional"===h.op)u=!d.validateRule(a,":filled",null,f);else if(!u||h.condition||":filled"===h.op)if(e=e.tagName?e:e[0],k=a===e?f:{value:d.getEffectiveValue(e)},k=d.validateRule(e,
h.op,h.arg,k),null!==k)if(h.neg&&(k=!k),h.condition&&k){if(!d.validateControl(a,h.rules,c,f,":blank"===h.op?!1:u))return!1}else if(!h.condition&&!k&&!d.isDisabled(e)){if(!c){var p=d.isArray(h.arg)?h.arg:[h.arg];b=h.msg.replace(/%(value|\d+)/g,function(b,c){return d.getValue("value"===c?e:a.form.elements.namedItem(p[c].control))});d.addError(e,b)}return!1}}return"number"!==a.type||a.validity.valid?!0:(c||d.addError(a,"Please enter a valid value."),!1)},validateForm:function(a,b){var c=a.form||a,f=
!1;d.formErrors=[];if(c["nette-submittedBy"]&&null!==c["nette-submittedBy"].getAttribute("formnovalidate"))if(f=d.parseJSON(c["nette-submittedBy"].getAttribute("data-nette-validation-scope")),f.length)f=new RegExp("^("+f.join("-|")+"-)");else return d.showFormErrors(c,[]),!0;var e={},g,l;for(g=0;g<c.elements.length;g++)if(l=c.elements[g],!l.tagName||l.tagName.toLowerCase()in{input:1,select:1,textarea:1,button:1}){if("radio"===l.type){if(e[l.name])continue;e[l.name]=!0}if(!(f&&!l.name.replace(/]\[|\[|]|$/g,
"-").match(f)||d.isDisabled(l)||d.validateControl(l,null,b)||d.formErrors.length))return!1}f=!d.formErrors.length;d.showFormErrors(c,d.formErrors);return f},isDisabled:function(a){if("radio"===a.type){for(var b=0,c=a.form.elements;b<c.length;b++)if(c[b].name===a.name&&!c[b].disabled)return!1;return!0}return a.disabled},addError:function(a,b){d.formErrors.push({element:a,message:b})},showFormErrors:function(a,b){for(var c=[],f,e=0;e<b.length;e++){var g=b[e].element,l=b[e].message;d.inArray(c,l)||(c.push(l),
!f&&g.focus&&(f=g))}c.length&&(alert(c.join("\n")),f&&f.focus())},expandRuleArgument:function(a,b){if(b&&b.control){var c=a.elements.namedItem(b.control),f={value:d.getEffectiveValue(c)};d.validateControl(c,null,!0,f);b=f.value}return b},validateRule:function(a,b,c,f){f=void 0===f?{value:d.getEffectiveValue(a)}:f;":"===b.charAt(0)&&(b=b.substr(1));b=b.replace("::","_");b=b.replace(/\\/g,"");for(var e=d.isArray(c)?c.slice(0):[c],g=0,l=e.length;g<l;g++)e[g]=d.expandRuleArgument(a.form,e[g]);return d.validators[b]?
d.validators[b](a,d.isArray(c)?e:e[0],f.value,f):null},validators:{filled:function(a,b,c){return"number"===a.type&&a.validity.badInput?!0:""!==c&&!1!==c&&null!==c&&(!d.isArray(c)||!!c.length)&&(!e.FileList||!(c instanceof e.FileList)||c.length)},blank:function(a,b,c){return!d.validators.filled(a,b,c)},valid:function(a,b,c){return d.validateControl(a,null,!0)},equal:function(a,b,c){function f(a){return"number"===typeof a||"string"===typeof a?""+a:!0===a?"1":""}if(void 0===b)return null;c=d.isArray(c)?
c:[c];b=d.isArray(b)?b:[b];a=0;var e=c.length;a:for(;a<e;a++){for(var g=0,l=b.length;g<l;g++)if(f(c[a])===f(b[g]))continue a;return!1}return!0},notEqual:function(a,b,c){return void 0===b?null:!d.validators.equal(a,b,c)},minLength:function(a,b,c){if("number"===a.type){if(a.validity.tooShort)return!1;if(a.validity.badInput)return null}return c.length>=b},maxLength:function(a,b,c){if("number"===a.type){if(a.validity.tooLong)return!1;if(a.validity.badInput)return null}return c.length<=b},length:function(a,
b,c){if("number"===a.type){if(a.validity.tooShort||a.validity.tooLong)return!1;if(a.validity.badInput)return null}b=d.isArray(b)?b:[b,b];return(null===b[0]||c.length>=b[0])&&(null===b[1]||c.length<=b[1])},email:function(a,b,c){return/^("([ !#-[\]-~]|\\[ -~])+"|[-a-z0-9!#$%&'*+\/=?^_`{|}~]+(\.[-a-z0-9!#$%&'*+\/=?^_`{|}~]+)*)@([0-9a-z\u00C0-\u02FF\u0370-\u1EFF]([-0-9a-z\u00C0-\u02FF\u0370-\u1EFF]{0,61}[0-9a-z\u00C0-\u02FF\u0370-\u1EFF])?\.)+[a-z\u00C0-\u02FF\u0370-\u1EFF]([-0-9a-z\u00C0-\u02FF\u0370-\u1EFF]{0,17}[a-z\u00C0-\u02FF\u0370-\u1EFF])?$/i.test(c)},
/*! netteForms.js | (c) 2004 David Grudl (https://davidgrudl.com) */
(function(e,p){if(e.JSON)if("function"===typeof define&&define.amd)define(function(){return p(e)});else if("object"===typeof module&&"object"===typeof module.exports)module.exports=p(e);else{var d=!e.Nette||!e.Nette.noInit;e.Nette=p(e);d&&e.Nette.initOnLoad()}})("undefined"!==typeof window?window:this,function(e){function p(a){return function(b){return a.call(this,b)}}var d={formErrors:[],version:"2.4",addEvent:function(a,b,c){"DOMContentLoaded"===b&&"loading"!==a.readyState?c.call(this):a.addEventListener?
a.addEventListener(b,c):"DOMContentLoaded"===b?a.attachEvent("onreadystatechange",function(){"complete"===a.readyState&&c.call(this)}):a.attachEvent("on"+b,p(c))},getValue:function(a){var b;if(a){if(a.tagName){if("radio"===a.type){var c=a.form.elements;for(b=0;b<c.length;b++)if(c[b].name===a.name&&c[b].checked)return c[b].value;return null}if("file"===a.type)return a.files||a.value;if("select"===a.tagName.toLowerCase()){b=a.selectedIndex;c=a.options;var f=[];if("select-one"===a.type)return 0>b?null:
c[b].value;for(b=0;b<c.length;b++)c[b].selected&&f.push(c[b].value);return f}if(a.name&&a.name.match(/\[\]$/)){c=a.form.elements[a.name].tagName?[a]:a.form.elements[a.name];f=[];for(b=0;b<c.length;b++)("checkbox"!==c[b].type||c[b].checked)&&f.push(c[b].value);return f}return"checkbox"===a.type?a.checked:"textarea"===a.tagName.toLowerCase()?a.value.replace("\r",""):a.value.replace("\r","").replace(/^\s+|\s+$/g,"")}return a[0]?d.getValue(a[0]):null}return null},getEffectiveValue:function(a){var b=d.getValue(a);
a.getAttribute&&b===a.getAttribute("data-nette-empty-value")&&(b="");return b},validateControl:function(a,b,c,f,q){a=a.tagName?a:a[0];b=b||d.parseJSON(a.getAttribute("data-nette-rules"));f=void 0===f?{value:d.getEffectiveValue(a)}:f;for(var g=0,k=b.length;g<k;g++){var h=b[g],l=h.op.match(/(~)?([^?]+)/),e=h.control?a.form.elements.namedItem(h.control):a;h.neg=l[1];h.op=l[2];h.condition=!!h.rules;if(e)if("optional"===h.op)q=!d.validateRule(a,":filled",null,f);else if(!q||h.condition||":filled"===h.op)if(e=
e.tagName?e:e[0],l=a===e?f:{value:d.getEffectiveValue(e)},l=d.validateRule(e,h.op,h.arg,l),null!==l)if(h.neg&&(l=!l),h.condition&&l){if(!d.validateControl(a,h.rules,c,f,":blank"===h.op?!1:q))return!1}else if(!h.condition&&!l&&!d.isDisabled(e)){if(!c){var p=d.isArray(h.arg)?h.arg:[h.arg];b=h.msg.replace(/%(value|\d+)/g,function(b,c){return d.getValue("value"===c?e:a.form.elements.namedItem(p[c].control))});d.addError(e,b)}return!1}}return"number"!==a.type||a.validity.valid?!0:(c||d.addError(a,"Please enter a valid value."),
!1)},validateForm:function(a,b){var c=a.form||a,f=!1;d.formErrors=[];if(c["nette-submittedBy"]&&null!==c["nette-submittedBy"].getAttribute("formnovalidate"))if(f=d.parseJSON(c["nette-submittedBy"].getAttribute("data-nette-validation-scope")),f.length)f=new RegExp("^("+f.join("-|")+"-)");else return d.showFormErrors(c,[]),!0;var e={},g;for(g=0;g<c.elements.length;g++){var k=c.elements[g];if(!k.tagName||k.tagName.toLowerCase()in{input:1,select:1,textarea:1,button:1}){if("radio"===k.type){if(e[k.name])continue;
e[k.name]=!0}if(!(f&&!k.name.replace(/]\[|\[|]|$/g,"-").match(f)||d.isDisabled(k)||d.validateControl(k,null,b)||d.formErrors.length))return!1}}f=!d.formErrors.length;d.showFormErrors(c,d.formErrors);return f},isDisabled:function(a){if("radio"===a.type){for(var b=0,c=a.form.elements;b<c.length;b++)if(c[b].name===a.name&&!c[b].disabled)return!1;return!0}return a.disabled},addError:function(a,b){d.formErrors.push({element:a,message:b})},showFormErrors:function(a,b){for(var c=[],f,e=0;e<b.length;e++){var g=
b[e].element,k=b[e].message;d.inArray(c,k)||(c.push(k),!f&&g.focus&&(f=g))}c.length&&(alert(c.join("\n")),f&&f.focus())},expandRuleArgument:function(a,b){if(b&&b.control){var c=a.elements.namedItem(b.control),f={value:d.getEffectiveValue(c)};d.validateControl(c,null,!0,f);b=f.value}return b}},t=!1;d.validateRule=function(a,b,c,f){f=void 0===f?{value:d.getEffectiveValue(a)}:f;":"===b.charAt(0)&&(b=b.substr(1));b=b.replace("::","_");b=b.replace(/\\/g,"");var e=d.isArray(c)?c.slice(0):[c];if(!t){t=!0;
for(var g=0,k=e.length;g<k;g++)e[g]=d.expandRuleArgument(a.form,e[g]);t=!1}return d.validators[b]?d.validators[b](a,d.isArray(c)?e:e[0],f.value,f):null};d.validators={filled:function(a,b,c){return"number"===a.type&&a.validity.badInput?!0:""!==c&&!1!==c&&null!==c&&(!d.isArray(c)||!!c.length)&&(!e.FileList||!(c instanceof e.FileList)||c.length)},blank:function(a,b,c){return!d.validators.filled(a,b,c)},valid:function(a){return d.validateControl(a,null,!0)},equal:function(a,b,c){function f(a){return"number"===
typeof a||"string"===typeof a?""+a:!0===a?"1":""}if(void 0===b)return null;c=d.isArray(c)?c:[c];b=d.isArray(b)?b:[b];a=0;var e=c.length;a:for(;a<e;a++){for(var g=0,k=b.length;g<k;g++)if(f(c[a])===f(b[g]))continue a;return!1}return!0},notEqual:function(a,b,c){return void 0===b?null:!d.validators.equal(a,b,c)},minLength:function(a,b,c){if("number"===a.type){if(a.validity.tooShort)return!1;if(a.validity.badInput)return null}return c.length>=b},maxLength:function(a,b,c){if("number"===a.type){if(a.validity.tooLong)return!1;
if(a.validity.badInput)return null}return c.length<=b},length:function(a,b,c){if("number"===a.type){if(a.validity.tooShort||a.validity.tooLong)return!1;if(a.validity.badInput)return null}b=d.isArray(b)?b:[b,b];return(null===b[0]||c.length>=b[0])&&(null===b[1]||c.length<=b[1])},email:function(a,b,c){return/^("([ !#-[\]-~]|\\[ -~])+"|[-a-z0-9!#$%&'*+/=?^_`{|}~]+(\.[-a-z0-9!#$%&'*+/=?^_`{|}~]+)*)@([0-9a-z\u00C0-\u02FF\u0370-\u1EFF]([-0-9a-z\u00C0-\u02FF\u0370-\u1EFF]{0,61}[0-9a-z\u00C0-\u02FF\u0370-\u1EFF])?\.)+[a-z\u00C0-\u02FF\u0370-\u1EFF]([-0-9a-z\u00C0-\u02FF\u0370-\u1EFF]{0,17}[a-z\u00C0-\u02FF\u0370-\u1EFF])?$/i.test(c)},
url:function(a,b,c,d){/^[a-z\d+.-]+:/.test(c)||(c="http://"+c);return/^https?:\/\/((([-_0-9a-z\u00C0-\u02FF\u0370-\u1EFF]+\.)*[0-9a-z\u00C0-\u02FF\u0370-\u1EFF]([-0-9a-z\u00C0-\u02FF\u0370-\u1EFF]{0,61}[0-9a-z\u00C0-\u02FF\u0370-\u1EFF])?\.)?[a-z\u00C0-\u02FF\u0370-\u1EFF]([-0-9a-z\u00C0-\u02FF\u0370-\u1EFF]{0,17}[a-z\u00C0-\u02FF\u0370-\u1EFF])?|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|\[[0-9a-f:]{3,39}\])(:\d{1,5})?(\/\S*)?$/i.test(c)?(d.value=c,!0):!1},regexp:function(a,b,c){a="string"===typeof b?b.match(/^\/(.*)\/([imu]*)$/):
!1;try{return a&&(new RegExp(a[1],a[2].replace("u",""))).test(c)}catch(d){}},pattern:function(a,b,c){try{return"string"===typeof b?(new RegExp("^(?:"+b+")$")).test(c):null}catch(d){}},integer:function(a,b,c){return"number"===a.type&&a.validity.badInput?!1:/^-?[0-9]+$/.test(c)},"float":function(a,b,c,d){if("number"===a.type&&a.validity.badInput)return!1;c=c.replace(" ","").replace(",",".");return/^-?[0-9]*[.,]?[0-9]+$/.test(c)?(d.value=c,!0):!1},min:function(a,b,c){if("number"===a.type){if(a.validity.rangeUnderflow)return!1;
if(a.validity.badInput)return null}return null===b||parseFloat(c)>=b},max:function(a,b,c){if("number"===a.type){if(a.validity.rangeOverflow)return!1;if(a.validity.badInput)return null}return null===b||parseFloat(c)<=b},range:function(a,b,c){if("number"===a.type){if(a.validity.rangeUnderflow||a.validity.rangeOverflow)return!1;if(a.validity.badInput)return null}return d.isArray(b)?(null===b[0]||parseFloat(c)>=b[0])&&(null===b[1]||parseFloat(c)<=b[1]):null},submitted:function(a,b,c){return a.form["nette-submittedBy"]===
a},fileSize:function(a,b,c){if(e.FileList)for(a=0;a<c.length;a++)if(c[a].size>b)return!1;return!0},image:function(a,b,c){if(e.FileList&&c instanceof e.FileList)for(a=0;a<c.length;a++)if((b=c[a].type)&&"image/gif"!==b&&"image/png"!==b&&"image/jpeg"!==b)return!1;return!0}},toggleForm:function(a,b){var c;d.toggles={};for(c=0;c<a.elements.length;c++)a.elements[c].tagName.toLowerCase()in{input:1,select:1,textarea:1,button:1}&&d.toggleControl(a.elements[c],null,null,!b);for(c in d.toggles)d.toggle(c,d.toggles[c],
b)},toggleControl:function(a,b,c,f,e){b=b||d.parseJSON(a.getAttribute("data-nette-rules"));e=void 0===e?{value:d.getEffectiveValue(a)}:e;for(var g=!1,l=[],h=function(){d.toggleForm(a.form,a)},k,p=0,v=b.length;p<v;p++){var n=b[p],r=n.op.match(/(~)?([^?]+)/),m=n.control?a.form.elements.namedItem(n.control):a;if(m){k=c;if(!1!==c){n.neg=r[1];n.op=r[2];k=a===m?e:{value:d.getEffectiveValue(m)};k=d.validateRule(m,n.op,n.arg,k);if(null===k)continue;else n.neg&&(k=!k);n.rules||(c=k)}if(n.rules&&d.toggleControl(a,
n.rules,k,f,e)||n.toggle){g=!0;if(f)for(var r=!document.addEventListener,w=m.tagName?m.name:m[0].name,m=m.tagName?m.form.elements:m,q=0;q<m.length;q++)m[q].name!==w||d.inArray(l,m[q])||(d.addEvent(m[q],r&&m[q].type in{checkbox:1,radio:1}?"click":"change",h),l.push(m[q]));for(var t in n.toggle||[])Object.prototype.hasOwnProperty.call(n.toggle,t)&&(d.toggles[t]=d.toggles[t]||(n.toggle[t]?k:!k))}}}return g},parseJSON:function(a){return"{op"===(a||"").substr(0,3)?eval("["+a+"]"):JSON.parse(a||"[]")},
toggle:function(a,b,c){if(a=document.getElementById(a))a.style.display=b?"":"none"},initForm:function(a){a.noValidate="novalidate";d.addEvent(a,"submit",function(b){d.validateForm(a)||(b&&b.stopPropagation?(b.stopPropagation(),b.preventDefault()):e.event&&(event.cancelBubble=!0,event.returnValue=!1))});d.toggleForm(a)},initOnLoad:function(){d.addEvent(document,"DOMContentLoaded",function(){for(var a=0;a<document.forms.length;a++)for(var b=document.forms[a],c=0;c<b.elements.length;c++)if(b.elements[c].getAttribute("data-nette-rules")){d.initForm(b);
break}d.addEvent(document.body,"click",function(a){a=a.target||a.srcElement;a.form&&a.type in{submit:1,image:1}&&(a.form["nette-submittedBy"]=a)})})},isArray:function(a){return"[object Array]"===Object.prototype.toString.call(a)},inArray:function(a,b){if([].indexOf)return-1<a.indexOf(b);for(var c=0;c<a.length;c++)if(a[c]===b)return!0;return!1},webalize:function(a){a=a.toLowerCase();var b="",c,e;for(c=0;c<a.length;c++)e=d.webalizeTable[a.charAt(c)],b+=e?e:a.charAt(c);return b.replace(/[^a-z0-9]+/g,
"-").replace(/^-|-$/g,"")},webalizeTable:{"\u00e1":"a","\u00e4":"a","\u010d":"c","\u010f":"d","\u00e9":"e","\u011b":"e","\u00ed":"i","\u013e":"l","\u0148":"n","\u00f3":"o","\u00f4":"o","\u0159":"r","\u0161":"s","\u0165":"t","\u00fa":"u","\u016f":"u","\u00fd":"y","\u017e":"z"}};return d});
!1;try{return a&&(new RegExp(a[1],a[2].replace("u",""))).test(c)}catch(f){}},pattern:function(a,b,c,d,q){if("string"!==typeof b)return null;try{try{var f=new RegExp("^(?:"+b+")$",q?"ui":"u")}catch(k){f=new RegExp("^(?:"+b+")$",q?"i":"")}if(e.FileList&&c instanceof FileList){for(a=0;a<c.length;a++)if(!f.test(c[a].name))return!1;return!0}return f.test(c)}catch(k){}},patternCaseInsensitive:function(a,b,c){return d.validators.pattern(a,b,c,null,!0)},integer:function(a,b,c){return"number"===a.type&&a.validity.badInput?
!1:/^-?[0-9]+$/.test(c)},"float":function(a,b,c,d){if("number"===a.type&&a.validity.badInput)return!1;c=c.replace(/ +/g,"").replace(/,/g,".");return/^-?[0-9]*\.?[0-9]+$/.test(c)?(d.value=c,!0):!1},min:function(a,b,c){if("number"===a.type){if(a.validity.rangeUnderflow)return!1;if(a.validity.badInput)return null}return null===b||parseFloat(c)>=b},max:function(a,b,c){if("number"===a.type){if(a.validity.rangeOverflow)return!1;if(a.validity.badInput)return null}return null===b||parseFloat(c)<=b},range:function(a,
b,c){if("number"===a.type){if(a.validity.rangeUnderflow||a.validity.rangeOverflow)return!1;if(a.validity.badInput)return null}return d.isArray(b)?(null===b[0]||parseFloat(c)>=b[0])&&(null===b[1]||parseFloat(c)<=b[1]):null},submitted:function(a){return a.form["nette-submittedBy"]===a},fileSize:function(a,b,c){if(e.FileList)for(a=0;a<c.length;a++)if(c[a].size>b)return!1;return!0},image:function(a,b,c){if(e.FileList&&c instanceof e.FileList)for(a=0;a<c.length;a++)if((b=c[a].type)&&"image/gif"!==b&&"image/png"!==
b&&"image/jpeg"!==b)return!1;return!0},"static":function(a,b){return b}};d.toggleForm=function(a,b){var c;d.toggles={};for(c=0;c<a.elements.length;c++)a.elements[c].tagName.toLowerCase()in{input:1,select:1,textarea:1,button:1}&&d.toggleControl(a.elements[c],null,null,!b);for(c in d.toggles)d.toggle(c,d.toggles[c],b)};d.toggleControl=function(a,b,c,f,e){b=b||d.parseJSON(a.getAttribute("data-nette-rules"));e=void 0===e?{value:d.getEffectiveValue(a)}:e;for(var g=!1,k=[],h=function(){d.toggleForm(a.form,
a)},l,p=0,q=b.length;p<q;p++){var n=b[p],u=n.op.match(/(~)?([^?]+)/),m=n.control?a.form.elements.namedItem(n.control):a;if(m){l=c;if(!1!==c){n.neg=u[1];n.op=u[2];l=a===m?e:{value:d.getEffectiveValue(m)};l=d.validateRule(m,n.op,n.arg,l);if(null===l)continue;else n.neg&&(l=!l);n.rules||(c=l)}if(n.rules&&d.toggleControl(a,n.rules,l,f,e)||n.toggle){g=!0;if(f){u=!document.addEventListener;var t=m.tagName?m.name:m[0].name;m=m.tagName?m.form.elements:m;for(var r=0;r<m.length;r++)m[r].name!==t||d.inArray(k,
m[r])||(d.addEvent(m[r],u&&m[r].type in{checkbox:1,radio:1}?"click":"change",h),k.push(m[r]))}for(var v in n.toggle||[])Object.prototype.hasOwnProperty.call(n.toggle,v)&&(d.toggles[v]=d.toggles[v]||(n.toggle[v]?l:!l))}}}return g};d.parseJSON=function(a){return"{op"===(a||"").substr(0,3)?eval("["+a+"]"):JSON.parse(a||"[]")};d.toggle=function(a,b,c){if(a=document.getElementById(a))a.style.display=b?"":"none"};d.initForm=function(a){d.toggleForm(a);a.noValidate||(a.noValidate=!0,d.addEvent(a,"submit",
function(b){d.validateForm(a)||(b&&b.stopPropagation?(b.stopPropagation(),b.preventDefault()):e.event&&(event.cancelBubble=!0,event.returnValue=!1))}))};d.initOnLoad=function(){d.addEvent(document,"DOMContentLoaded",function(){for(var a=0;a<document.forms.length;a++)for(var b=document.forms[a],c=0;c<b.elements.length;c++)if(b.elements[c].getAttribute("data-nette-rules")){d.initForm(b);break}d.addEvent(document.body,"click",function(a){for(a=a.target||a.srcElement;a;){if(a.form&&a.type in{submit:1,
image:1}){a.form["nette-submittedBy"]=a;break}a=a.parentNode}})})};d.isArray=function(a){return"[object Array]"===Object.prototype.toString.call(a)};d.inArray=function(a,b){if([].indexOf)return-1<a.indexOf(b);for(var c=0;c<a.length;c++)if(a[c]===b)return!0;return!1};d.webalize=function(a){a=a.toLowerCase();var b="",c;for(c=0;c<a.length;c++){var e=d.webalizeTable[a.charAt(c)];b+=e?e:a.charAt(c)}return b.replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")};d.webalizeTable={"\u00e1":"a","\u00e4":"a","\u010d":"c",
"\u010f":"d","\u00e9":"e","\u011b":"e","\u00ed":"i","\u013e":"l","\u0148":"n","\u00f3":"o","\u00f4":"o","\u0159":"r","\u0161":"s","\u0165":"t","\u00fa":"u","\u016f":"u","\u00fd":"y","\u017e":"z"};return d});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc