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

nette-forms

Package Overview
Dependencies
Maintainers
0
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 3.5.0 to 3.5.1

4

package.json
{
"name": "nette-forms",
"version": "3.5.0",
"version": "3.5.1",
"description": "Client side script for Nette Forms Component",

@@ -14,2 +14,4 @@ "keywords": [

"main": "src/assets/netteForms.js",
"types": "src/assets/netteForms.d.ts",
"unpkg": "src/assets/netteForms.min.js",
"files": [

@@ -16,0 +18,0 @@ "src/assets"

@@ -302,4 +302,4 @@ /*!

this.formErrors = [];
if (form['nette-submittedBy'] && form['nette-submittedBy'].getAttribute('formnovalidate') !== null) {
let scopeArr = JSON.parse(form['nette-submittedBy'].getAttribute('data-nette-validation-scope') ?? '[]');
if (sender.getAttribute('formnovalidate') !== null) {
let scopeArr = JSON.parse(sender.getAttribute('data-nette-validation-scope') ?? '[]');
if (scopeArr.length) {

@@ -523,3 +523,3 @@ scope = new RegExp('^(' + scopeArr.join('-|') + '-)');

form.addEventListener('submit', (e) => {
if (!this.validateForm(form)) {
if (!this.validateForm(form.submitter || form)) {
e.stopPropagation();

@@ -537,12 +537,2 @@ e.preventDefault();

.forEach((form) => this.initForm(form));
document.body.addEventListener('click', (e) => {
let target = e.target;
while (target) {
if (target.form && target.type in { submit: 1, image: 1 }) {
target.form['nette-submittedBy'] = target;
break;
}
target = target.parentNode;
}
});
});

@@ -549,0 +539,0 @@ }

@@ -7,2 +7,2 @@ /*!

*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self,e.Nette?.noInit?e.Nette=t():(e.Nette=t()).initOnLoad())}(this,(function(){"use strict";class e{filled(e,t,r){return""!==r&&!1!==r&&null!==r&&(!Array.isArray(r)||r.length>0)&&(!(r instanceof FileList)||r.length>0)}blank(e,t,r){return!this.filled(e,t,r)}valid(e,t){return t.validateControl(e,void 0,!0)}equal(e,t,r){if(void 0===t)return null;let n=e=>"number"==typeof e||"string"==typeof e?""+e:!0===e?"1":"",i=Array.isArray(r)?r:[r],l=Array.isArray(t)?t:[t];e:for(let e of i){for(let t of l)if(n(e)===n(t))continue e;return!1}return i.length>0}notEqual(e,t,r){return void 0===t?null:!this.equal(e,t,r)}minLength(e,t,r){return(r="number"==typeof r?r.toString():r).length>=t}maxLength(e,t,r){return(r="number"==typeof r?r.toString():r).length<=t}length(e,t,r){return r="number"==typeof r?r.toString():r,(null===(t=Array.isArray(t)?t:[t,t])[0]||r.length>=t[0])&&(null===t[1]||r.length<=t[1])}email(e,t,r){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(r)}url(e,t,r,n){return/^[a-z\d+.-]+:/.test(r)||(r="https://"+r),!!/^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(r)&&(n.value=r,!0)}regexp(e,t,r){let n="string"==typeof t&&t.match(/^\/(.*)\/([imu]*)$/);try{return n&&new RegExp(n[1],n[2].replace("u","")).test(r)}catch{return null}}pattern(e,t,r,n,i){if("string"!=typeof t)return null;try{let e;try{e=new RegExp("^(?:"+t+")$",i?"ui":"u")}catch{e=new RegExp("^(?:"+t+")$",i?"i":"")}return r instanceof FileList?Array.from(r).every((t=>e.test(t.name))):e.test(r)}catch{return null}}patternCaseInsensitive(e,t,r){return this.pattern(e,t,r,null,!0)}numeric(e,t,r){return/^[0-9]+$/.test(r)}integer(e,t,r,n){return!!/^-?[0-9]+$/.test(r)&&(n.value=parseFloat(r),!0)}float(e,t,r,n){return r=r.replace(/ +/g,"").replace(/,/g,"."),!!/^-?[0-9]*\.?[0-9]+$/.test(r)&&(n.value=parseFloat(r),!0)}min(e,t,r){return Number.isFinite(t)&&(r=parseFloat(r)),r>=t}max(e,t,r){return Number.isFinite(t)&&(r=parseFloat(r)),r<=t}range(e,t,r){return Array.isArray(t)?"time"===e.type&&t[0]>t[1]?r>=t[0]||r<=t[1]:(null===t[0]||this.min(e,t[0],r))&&(null===t[1]||this.max(e,t[1],r)):null}submitted(e){return e.form["nette-submittedBy"]===e}fileSize(e,t,r){return Array.from(r).every((e=>e.size<=t))}mimeType(e,t,r){let n=[];(t=Array.isArray(t)?t:[t]).forEach((e=>n.push("^"+e.replace(/([^\w])/g,"\\$1").replace("\\*",".*")+"$")));let i=new RegExp(n.join("|"));return Array.from(r).every((e=>!e.type||i.test(e.type)))}image(e,t,r){return this.mimeType(e,t??["image/gif","image/png","image/jpeg","image/webp"],r)}static(e,t){return t}}let t={"á":"a","ä":"a","č":"c","ď":"d","é":"e","ě":"e","í":"i","ľ":"l","ň":"n","ó":"o","ô":"o","ř":"r","š":"s","ť":"t","ú":"u","ů":"u","ý":"y","ž":"z"};let r=new class{formErrors=[];validators=new e;#e={};#t={};#r=new WeakMap;#n(e,t){let r=e.elements.namedItem(t);return r instanceof RadioNodeList?r[0]:r}#i(e){let t=e.form.elements.namedItem(e.name);return t instanceof RadioNodeList?Array.from(t):[t]}#l(e){"loading"!==document.readyState?e.call(this):document.addEventListener("DOMContentLoaded",e)}getValue(e){return e instanceof HTMLInputElement?"radio"===e.type?this.#i(e).find((e=>e.checked))?.value??null:"file"===e.type?e.files:"checkbox"===e.type?e.name.endsWith("[]")?this.#i(e).filter((e=>e.checked)).map((e=>e.value)):e.checked:e.value.trim():e instanceof HTMLSelectElement?e.multiple?Array.from(e.selectedOptions,(e=>e.value)):e.selectedOptions[0]?.value??null:e instanceof HTMLTextAreaElement?e.value:e instanceof RadioNodeList?this.getValue(e[0]):null}getEffectiveValue(e,t=!1){let r=this.getValue(e);if(r===e.getAttribute("data-nette-empty-value")&&(r=""),t&&void 0===this.#e[e.name]){this.#e[e.name]=!0;let t={value:r};this.validateControl(e,void 0,!0,t),r=t.value,delete this.#e[e.name]}return r}validateControl(e,t,r=!1,n,i){t??=JSON.parse(e.getAttribute("data-nette-rules")??"[]"),n??={value:this.getEffectiveValue(e)},i??=!this.validateRule(e,":filled",null,n);for(let l of t){let t=l.op.match(/(~)?([^?]+)/),a=l.control?this.#n(e.form,l.control):e;if(l.neg=!!t[1],l.op=t[2],l.condition=!!l.rules,!a)continue;if(i&&!l.condition&&":filled"!==l.op)continue;let o=this.validateRule(a,l.op,l.arg,e===a?n:void 0);if(null!==o)if(l.neg&&(o=!o),l.condition&&o){if(!this.validateControl(e,l.rules,r,n,":blank"!==l.op&&i))return!1}else if(!l.condition&&!o){if(this.isDisabled(a))continue;if(!r){let t=Array.isArray(l.arg)?l.arg:[l.arg],r=l.msg.replace(/%(value|\d+)/g,((r,n)=>this.getValue("value"===n?a:e.form.elements.namedItem(t[n].control))));this.addError(a,r)}return!1}}return!0}validateForm(e,t=!1){let r,n=e.form??e;if(this.formErrors=[],n["nette-submittedBy"]&&null!==n["nette-submittedBy"].getAttribute("formnovalidate")){let e=JSON.parse(n["nette-submittedBy"].getAttribute("data-nette-validation-scope")??"[]");if(!e.length)return this.showFormErrors(n,[]),!0;r=new RegExp("^("+e.join("-|")+"-)")}for(let e of n.elements)if(e.willValidate&&e.validity.badInput)return e.reportValidity(),!1;for(let e of n.elements)if(e.getAttribute("data-nette-rules")&&(!r||e.name.replace(/]\[|\[|]|$/g,"-").match(r))&&!this.isDisabled(e)&&!this.validateControl(e,void 0,t)&&!this.formErrors.length)return!1;let i=!this.formErrors.length;return this.showFormErrors(n,this.formErrors),i}isDisabled(e){return"radio"===e.type?this.#i(e).every((e=>e.disabled)):e.disabled}addError(e,t){this.formErrors.push({element:e,message:t})}showFormErrors(e,t){let r,n=[];for(let e of t)n.indexOf(e.message)<0&&(n.push(e.message),r??=e.element);n.length&&this.showModal(n.join("\n"),(()=>{r?.focus()}))}showModal(e,t){let r=document.createElement("dialog");if(!r.showModal)return alert(e),void t();let n=document.createElement("style");n.innerText=".netteFormsModal { text-align: center; margin: auto; border: 2px solid black; padding: 1rem } .netteFormsModal button { padding: .1em 2em }";let i=document.createElement("button");i.innerText="OK",i.onclick=()=>{r.remove(),t()},r.setAttribute("class","netteFormsModal"),r.innerText=e+"\n\n",r.append(n,i),document.body.append(r),r.showModal()}validateRule(e,t,r,n){if(e.validity.badInput)return":filled"===t;n??={value:this.getEffectiveValue(e,!0)};let i=":"===t.charAt(0)?t.substring(1):t;i=i.replace("::","_").replaceAll("\\","");let l=Array.isArray(r)?r:[r];return l=l.map((t=>{if(t?.control){let r=this.#n(e.form,t.control);return r===e?n.value:this.getEffectiveValue(r,!0)}return t})),"valid"===i&&(l[0]=this),this.validators[i]?this.validators[i](e,Array.isArray(r)?l:l[0],n.value,n):null}toggleForm(e,t){this.#t={};for(let r of Array.from(e.elements))r.getAttribute("data-nette-rules")&&this.toggleControl(r,void 0,null,!t);for(let e in this.#t)this.toggle(e,this.#t[e].state,this.#t[e].elem,t)}toggleControl(e,t,r=null,n=!1,i,l){t??=JSON.parse(e.getAttribute("data-nette-rules")??"[]"),i??={value:this.getEffectiveValue(e)},l??=!this.validateRule(e,":filled",null,i);let a,o=!1;for(let s of t){let t=s.op.match(/(~)?([^?]+)/),u=s.control?this.#n(e.form,s.control):e;if(s.neg=!!t[1],s.op=t[2],s.condition=!!s.rules,u&&(!l||s.condition||":filled"===s.op)){if(a=r,!1!==r){if(a=this.validateRule(u,s.op,s.arg,e===u?i:void 0),null===a)continue;s.neg&&(a=!a),s.condition||(r=a)}if(s.condition&&this.toggleControl(e,s.rules,a,n,i,":blank"!==s.op&&l)||s.toggle){o=!0,n&&this.#i(u).filter((e=>!this.#r.has(e))).forEach((t=>{t.addEventListener("change",(t=>this.toggleForm(e.form,t))),this.#r.set(t,null)}));for(let t in s.toggle??{})this.#t[t]??={elem:e,state:!1},this.#t[t].state||=s.toggle[t]?!!a:!a}}}return o}toggle(e,t,r,n){/^\w[\w.:-]*$/.test(e)&&(e="#"+e),Array.from(document.querySelectorAll(e)).forEach((e=>e.hidden=!t))}compactCheckboxes(e,t){let r={};for(let n of e.elements)n instanceof HTMLInputElement&&"checkbox"===n.type&&n.name.endsWith("[]")&&n.checked&&!n.disabled&&(t.delete(n.name),r[n.name]??=[],r[n.name].push(n.value));for(let e in r)t.set(e.substring(0,e.length-2),r[e].join(","))}initForm(e){"get"===e.method&&e.hasAttribute("data-nette-compact")&&e.addEventListener("formdata",(t=>this.compactCheckboxes(e,t.formData))),Array.from(e.elements).some((e=>e.getAttribute("data-nette-rules")))&&(this.toggleForm(e),e.noValidate||(e.noValidate=!0,e.addEventListener("submit",(t=>{this.validateForm(e)||(t.stopPropagation(),t.preventDefault())})),e.addEventListener("reset",(()=>{setTimeout((()=>this.toggleForm(e)))}))))}initOnLoad(){this.#l((()=>{Array.from(document.forms).forEach((e=>this.initForm(e))),document.body.addEventListener("click",(e=>{let t=e.target;for(;t;){if(t.form&&t.type in{submit:1,image:1}){t.form["nette-submittedBy"]=t;break}t=t.parentNode}}))}))}};return r.version="3.5.0",r.webalize=function(e){e=e.toLowerCase();let r="";for(let n=0;n<e.length;n++){let i=t[e.charAt(n)];r+=i||e.charAt(n)}return r.replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")},r}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self,e.Nette?.noInit?e.Nette=t():(e.Nette=t()).initOnLoad())}(this,(function(){"use strict";class e{filled(e,t,r){return""!==r&&!1!==r&&null!==r&&(!Array.isArray(r)||r.length>0)&&(!(r instanceof FileList)||r.length>0)}blank(e,t,r){return!this.filled(e,t,r)}valid(e,t){return t.validateControl(e,void 0,!0)}equal(e,t,r){if(void 0===t)return null;let n=e=>"number"==typeof e||"string"==typeof e?""+e:!0===e?"1":"",l=Array.isArray(r)?r:[r],i=Array.isArray(t)?t:[t];e:for(let e of l){for(let t of i)if(n(e)===n(t))continue e;return!1}return l.length>0}notEqual(e,t,r){return void 0===t?null:!this.equal(e,t,r)}minLength(e,t,r){return(r="number"==typeof r?r.toString():r).length>=t}maxLength(e,t,r){return(r="number"==typeof r?r.toString():r).length<=t}length(e,t,r){return r="number"==typeof r?r.toString():r,(null===(t=Array.isArray(t)?t:[t,t])[0]||r.length>=t[0])&&(null===t[1]||r.length<=t[1])}email(e,t,r){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(r)}url(e,t,r,n){return/^[a-z\d+.-]+:/.test(r)||(r="https://"+r),!!/^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(r)&&(n.value=r,!0)}regexp(e,t,r){let n="string"==typeof t&&t.match(/^\/(.*)\/([imu]*)$/);try{return n&&new RegExp(n[1],n[2].replace("u","")).test(r)}catch{return null}}pattern(e,t,r,n,l){if("string"!=typeof t)return null;try{let e;try{e=new RegExp("^(?:"+t+")$",l?"ui":"u")}catch{e=new RegExp("^(?:"+t+")$",l?"i":"")}return r instanceof FileList?Array.from(r).every((t=>e.test(t.name))):e.test(r)}catch{return null}}patternCaseInsensitive(e,t,r){return this.pattern(e,t,r,null,!0)}numeric(e,t,r){return/^[0-9]+$/.test(r)}integer(e,t,r,n){return!!/^-?[0-9]+$/.test(r)&&(n.value=parseFloat(r),!0)}float(e,t,r,n){return r=r.replace(/ +/g,"").replace(/,/g,"."),!!/^-?[0-9]*\.?[0-9]+$/.test(r)&&(n.value=parseFloat(r),!0)}min(e,t,r){return Number.isFinite(t)&&(r=parseFloat(r)),r>=t}max(e,t,r){return Number.isFinite(t)&&(r=parseFloat(r)),r<=t}range(e,t,r){return Array.isArray(t)?"time"===e.type&&t[0]>t[1]?r>=t[0]||r<=t[1]:(null===t[0]||this.min(e,t[0],r))&&(null===t[1]||this.max(e,t[1],r)):null}submitted(e){return e.form["nette-submittedBy"]===e}fileSize(e,t,r){return Array.from(r).every((e=>e.size<=t))}mimeType(e,t,r){let n=[];(t=Array.isArray(t)?t:[t]).forEach((e=>n.push("^"+e.replace(/([^\w])/g,"\\$1").replace("\\*",".*")+"$")));let l=new RegExp(n.join("|"));return Array.from(r).every((e=>!e.type||l.test(e.type)))}image(e,t,r){return this.mimeType(e,t??["image/gif","image/png","image/jpeg","image/webp"],r)}static(e,t){return t}}let t={"á":"a","ä":"a","č":"c","ď":"d","é":"e","ě":"e","í":"i","ľ":"l","ň":"n","ó":"o","ô":"o","ř":"r","š":"s","ť":"t","ú":"u","ů":"u","ý":"y","ž":"z"};let r=new class{formErrors=[];validators=new e;#e={};#t={};#r=new WeakMap;#n(e,t){let r=e.elements.namedItem(t);return r instanceof RadioNodeList?r[0]:r}#l(e){let t=e.form.elements.namedItem(e.name);return t instanceof RadioNodeList?Array.from(t):[t]}#i(e){"loading"!==document.readyState?e.call(this):document.addEventListener("DOMContentLoaded",e)}getValue(e){return e instanceof HTMLInputElement?"radio"===e.type?this.#l(e).find((e=>e.checked))?.value??null:"file"===e.type?e.files:"checkbox"===e.type?e.name.endsWith("[]")?this.#l(e).filter((e=>e.checked)).map((e=>e.value)):e.checked:e.value.trim():e instanceof HTMLSelectElement?e.multiple?Array.from(e.selectedOptions,(e=>e.value)):e.selectedOptions[0]?.value??null:e instanceof HTMLTextAreaElement?e.value:e instanceof RadioNodeList?this.getValue(e[0]):null}getEffectiveValue(e,t=!1){let r=this.getValue(e);if(r===e.getAttribute("data-nette-empty-value")&&(r=""),t&&void 0===this.#e[e.name]){this.#e[e.name]=!0;let t={value:r};this.validateControl(e,void 0,!0,t),r=t.value,delete this.#e[e.name]}return r}validateControl(e,t,r=!1,n,l){t??=JSON.parse(e.getAttribute("data-nette-rules")??"[]"),n??={value:this.getEffectiveValue(e)},l??=!this.validateRule(e,":filled",null,n);for(let i of t){let t=i.op.match(/(~)?([^?]+)/),a=i.control?this.#n(e.form,i.control):e;if(i.neg=!!t[1],i.op=t[2],i.condition=!!i.rules,!a)continue;if(l&&!i.condition&&":filled"!==i.op)continue;let o=this.validateRule(a,i.op,i.arg,e===a?n:void 0);if(null!==o)if(i.neg&&(o=!o),i.condition&&o){if(!this.validateControl(e,i.rules,r,n,":blank"!==i.op&&l))return!1}else if(!i.condition&&!o){if(this.isDisabled(a))continue;if(!r){let t=Array.isArray(i.arg)?i.arg:[i.arg],r=i.msg.replace(/%(value|\d+)/g,((r,n)=>this.getValue("value"===n?a:e.form.elements.namedItem(t[n].control))));this.addError(a,r)}return!1}}return!0}validateForm(e,t=!1){let r,n=e.form??e;if(this.formErrors=[],null!==e.getAttribute("formnovalidate")){let t=JSON.parse(e.getAttribute("data-nette-validation-scope")??"[]");if(!t.length)return this.showFormErrors(n,[]),!0;r=new RegExp("^("+t.join("-|")+"-)")}for(let e of n.elements)if(e.willValidate&&e.validity.badInput)return e.reportValidity(),!1;for(let e of n.elements)if(e.getAttribute("data-nette-rules")&&(!r||e.name.replace(/]\[|\[|]|$/g,"-").match(r))&&!this.isDisabled(e)&&!this.validateControl(e,void 0,t)&&!this.formErrors.length)return!1;let l=!this.formErrors.length;return this.showFormErrors(n,this.formErrors),l}isDisabled(e){return"radio"===e.type?this.#l(e).every((e=>e.disabled)):e.disabled}addError(e,t){this.formErrors.push({element:e,message:t})}showFormErrors(e,t){let r,n=[];for(let e of t)n.indexOf(e.message)<0&&(n.push(e.message),r??=e.element);n.length&&this.showModal(n.join("\n"),(()=>{r?.focus()}))}showModal(e,t){let r=document.createElement("dialog");if(!r.showModal)return alert(e),void t();let n=document.createElement("style");n.innerText=".netteFormsModal { text-align: center; margin: auto; border: 2px solid black; padding: 1rem } .netteFormsModal button { padding: .1em 2em }";let l=document.createElement("button");l.innerText="OK",l.onclick=()=>{r.remove(),t()},r.setAttribute("class","netteFormsModal"),r.innerText=e+"\n\n",r.append(n,l),document.body.append(r),r.showModal()}validateRule(e,t,r,n){if(e.validity.badInput)return":filled"===t;n??={value:this.getEffectiveValue(e,!0)};let l=":"===t.charAt(0)?t.substring(1):t;l=l.replace("::","_").replaceAll("\\","");let i=Array.isArray(r)?r:[r];return i=i.map((t=>{if(t?.control){let r=this.#n(e.form,t.control);return r===e?n.value:this.getEffectiveValue(r,!0)}return t})),"valid"===l&&(i[0]=this),this.validators[l]?this.validators[l](e,Array.isArray(r)?i:i[0],n.value,n):null}toggleForm(e,t){this.#t={};for(let r of Array.from(e.elements))r.getAttribute("data-nette-rules")&&this.toggleControl(r,void 0,null,!t);for(let e in this.#t)this.toggle(e,this.#t[e].state,this.#t[e].elem,t)}toggleControl(e,t,r=null,n=!1,l,i){t??=JSON.parse(e.getAttribute("data-nette-rules")??"[]"),l??={value:this.getEffectiveValue(e)},i??=!this.validateRule(e,":filled",null,l);let a,o=!1;for(let s of t){let t=s.op.match(/(~)?([^?]+)/),u=s.control?this.#n(e.form,s.control):e;if(s.neg=!!t[1],s.op=t[2],s.condition=!!s.rules,u&&(!i||s.condition||":filled"===s.op)){if(a=r,!1!==r){if(a=this.validateRule(u,s.op,s.arg,e===u?l:void 0),null===a)continue;s.neg&&(a=!a),s.condition||(r=a)}if(s.condition&&this.toggleControl(e,s.rules,a,n,l,":blank"!==s.op&&i)||s.toggle){o=!0,n&&this.#l(u).filter((e=>!this.#r.has(e))).forEach((t=>{t.addEventListener("change",(t=>this.toggleForm(e.form,t))),this.#r.set(t,null)}));for(let t in s.toggle??{})this.#t[t]??={elem:e,state:!1},this.#t[t].state||=s.toggle[t]?!!a:!a}}}return o}toggle(e,t,r,n){/^\w[\w.:-]*$/.test(e)&&(e="#"+e),Array.from(document.querySelectorAll(e)).forEach((e=>e.hidden=!t))}compactCheckboxes(e,t){let r={};for(let n of e.elements)n instanceof HTMLInputElement&&"checkbox"===n.type&&n.name.endsWith("[]")&&n.checked&&!n.disabled&&(t.delete(n.name),r[n.name]??=[],r[n.name].push(n.value));for(let e in r)t.set(e.substring(0,e.length-2),r[e].join(","))}initForm(e){"get"===e.method&&e.hasAttribute("data-nette-compact")&&e.addEventListener("formdata",(t=>this.compactCheckboxes(e,t.formData))),Array.from(e.elements).some((e=>e.getAttribute("data-nette-rules")))&&(this.toggleForm(e),e.noValidate||(e.noValidate=!0,e.addEventListener("submit",(t=>{this.validateForm(e.submitter||e)||(t.stopPropagation(),t.preventDefault())})),e.addEventListener("reset",(()=>{setTimeout((()=>this.toggleForm(e)))}))))}initOnLoad(){this.#i((()=>{Array.from(document.forms).forEach((e=>this.initForm(e)))}))}};return r.version="3.5.0",r.webalize=function(e){e=e.toLowerCase();let r="";for(let n=0;n<e.length;n++){let l=t[e.charAt(n)];r+=l||e.charAt(n)}return r.replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")},r}));
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