forked from javascript-indonesias/nwjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnw.js
1 lines (1 loc) · 4.59 KB
/
nw.js
1
/*! nwJS | (c) Muhammad Fauzan | github.com/fauzan121002/nwjs/license.md */ class Nw{constructor(){this.inputCount=0,this.totalInputCount=0}start(){let t=document.querySelectorAll("form[validate] input[type=text],input[type=checkbox],textarea,input[type=password],input[type=email],input[type=file],input[type=radio],input[type=number]");for(let o of t)this.inputCount=this.inputCount+1,this.totalInputCount=this.totalInputCount+1;document.querySelectorAll("form[validate]").forEach(t=>{let o=t;t.addEventListener("submit",t=>{t.preventDefault(),document.querySelectorAll("form[validate] input[type=text]").forEach(t=>{if(""===t.value){let o=t.id;document.querySelectorAll("[error="+o+"]").forEach(t=>{t.style.fontSize="12px",t.style.color="red",t.innerHTML="Please fill the "+o}),this.inputCount=this.inputCount+1,(this.inputCount>this.totalInputCount||this.inputCount<this.totalInputCount)&&(this.inputCount=this.totalInputCount),t.style.boxShadow="0px 0px 3px red"}else t.style.boxShadow="",this.inputCount=this.inputCount-1,0==this.inputCount&&o.submit()}),document.querySelectorAll("form[validate] textarea").forEach(t=>{if(""==t.value){let o=t.id;document.querySelectorAll("[error="+o+"]").forEach(t=>{t.style.fontSize="12px",t.style.color="red",t.innerHTML="Please fill the "+o}),this.inputCount=this.inputCount+1,(this.inputCount>this.totalInputCount||this.inputCount<this.totalInputCount)&&(this.inputCount=this.totalInputCount),t.style.boxShadow="0px 0px 3px red"}else t.style.boxShadow="",this.inputCount=this.inputCount-1,0==this.inputCount&&o.submit()}),document.querySelectorAll("form[validate] input[type=checkbox]").forEach(t=>{if(0==t.checked){let o=t.id;document.querySelectorAll("[error="+o+"]").forEach(t=>{t.style.fontSize="12px",t.style.color="red",t.innerHTML="Please choose one of "+o}),this.inputCount=this.inputCount+1,(this.inputCount>this.totalInputCount||this.inputCount<this.totalInputCount)&&(this.inputCount=this.totalInputCount),t.style.boxShadow="0px 0px 3px red"}else t.style.boxShadow="",this.inputCount=this.inputCount-1,0==this.inputCount&&o.submit()}),document.querySelectorAll("form[validate] input[type=password]").forEach(t=>{if(""==t.value){let o=t.id;document.querySelectorAll("[error="+o+"]").forEach(t=>{t.style.fontSize="12px",t.style.color="red",t.innerHTML="Please fill the "+o}),this.inputCount=this.inputCount+1,(this.inputCount>this.totalInputCount||this.inputCount<this.totalInputCount)&&(this.inputCount=this.totalInputCount),t.style.boxShadow="0px 0px 3px red"}else t.style.boxShadow="",this.inputCount=this.inputCount-1,0==this.inputCount&&o.submit()}),document.querySelectorAll("form[validate] input[type=email]").forEach(t=>{if(""==t.value){let o=t.id;document.querySelectorAll("[error="+o+"]").forEach(t=>{t.style.fontSize="12px",t.style.color="red",t.innerHTML="Please fill the "+o}),this.inputCount=this.inputCount+1,(this.inputCount>this.totalInputCount||this.inputCount<this.totalInputCount)&&(this.inputCount=this.totalInputCount),t.style.boxShadow="0px 0px 3px red"}else t.style.boxShadow="",this.inputCount=this.inputCount-1,0==this.inputCount&&o.submit()}),document.querySelectorAll("form[validate] input[type=file]").forEach(t=>{if(0==t.files.length){let o=t.id;document.querySelectorAll("[error="+o+"]").forEach(t=>{t.style.fontSize="12px",t.style.color="red",t.innerHTML="Please upload the file of "+o}),this.inputCount=this.inputCount+1,(this.inputCount>this.totalInputCount||this.inputCount<this.totalInputCount)&&(this.inputCount=this.totalInputCount),t.style.color="red"}else t.style.color="black",this.inputCount=this.inputCount-1,0==this.inputCount&&o.submit()}),document.querySelectorAll("form[validate] input[type=radio]").forEach(t=>{if(0==t.checked){let o=t.id;document.querySelectorAll("[error="+o+"]").forEach(t=>{t.style.fontSize="12px",t.style.color="red",t.innerHTML="Please choose one of "+o}),this.inputCount=this.inputCount+1,(this.inputCount>this.totalInputCount||this.inputCount<this.totalInputCount)&&(this.inputCount=this.totalInputCount),t.style.boxShadow="0px 0px 3px red"}else t.style.boxShadow="",this.inputCount=this.inputCount-1,0==this.inputCount&&o.submit()}),document.querySelectorAll("form[validate] input[type=number]").forEach(t=>{if(""==t.value){let o=t.id;document.querySelectorAll("[error="+o+"]").forEach(t=>{t.style.fontSize="12px",t.style.color="red",t.innerHTML="Please fill the "+o}),this.inputCount=this.inputCount+1,(this.inputCount>this.totalInputCount||this.inputCount<this.totalInputCount)&&(this.inputCount=this.totalInputCount),t.style.boxShadow="0px 0px 3px red"}else t.style.boxShadow="",this.inputCount=this.inputCount-1,0==this.inputCount&&o.submit()})})})}}(new Nw).start();