{"version":3,"sources":["webpack:///./src/js/modules/legacy/customForm.js"],"names":["Module","this","dom","inputs","el","querySelectorAll","radioGroups","dropdowns","datepickers","setAttribute","forEach","dropdown","parentNode","classList","add","Dropdown","datepicker","DatePicker","input","value","addEventListener","e","target","remove","handleSubmit","bind","validateForm","preventDefault","isValid","required","trim","focus","radioGroup","requiredRadio","find","some","checked","Component"],"mappings":"8/EAKMA,E,0WACJ,WACEC,KAAKC,IAAM,CACTC,OAAQF,KAAKG,GAAGC,iBAAiB,wCACjCC,YAAaL,KAAKG,GAAGC,iBAAiB,oCACtCE,UAAWN,KAAKG,GAAGC,iBAAiB,8BACpCG,YAAaP,KAAKG,GAAGC,iBACnB,yCAIJJ,KAAKG,GAAGK,aAAa,aAAc,cAGnCR,KAAKC,IAAIK,UAAUG,SAAQ,SAAAC,GACzBA,EAASC,WAAWA,WAAWC,UAAUC,IAAI,kBAC7C,IAAIC,IAASJ,MAIfV,KAAKC,IAAIM,YAAYE,SAAQ,SAAAM,GAC3B,IAAIC,IAAWD,Q,0BAInB,WACEf,KAAKC,IAAIC,OAAOO,SAAQ,SAAAQ,GAClBA,EAAMC,OACRD,EAAMN,WAAWC,UAAUC,IAAI,UAGjCI,EAAME,iBAAiB,SAAS,SAAAC,GAC9BA,EAAEC,OAAOV,WAAWC,UAAUC,IAAI,aAGpCI,EAAME,iBAAiB,QAAQ,SAAAC,GACxBA,EAAEC,OAAOH,OACZE,EAAEC,OAAOV,WAAWC,UAAUU,OAAO,gBAK3CtB,KAAKG,GAAGgB,iBAAiB,SAAUnB,KAAKuB,aAAaC,KAAKxB,S,sDAG5D,WAAmBoB,GAAnB,gFACOpB,KAAKyB,gBACRL,EAAEM,iBAFN,+C,wPAMA,WACE,IAAIC,GAAU,EAkCd,OAhCA3B,KAAKC,IAAIC,OAAOO,SAAQ,SAAAQ,GACtBA,EAAMN,WAAWC,UAAUU,OAAO,SAC9BL,EAAMW,WAAaX,EAAMC,MAAMW,SACjCZ,EAAMN,WAAWC,UAAUC,IAAI,SAC3Bc,GACFV,EAAMa,QAERH,GAAU,MAId3B,KAAKC,IAAII,YAAYI,SAAQ,SAAAsB,GAC3BA,EAAWnB,UAAUU,OAAO,SAC5B,IAAMU,EAAgB,EAAID,EAAW3B,iBAAiB,UAAU6B,MAC9D,SAAAhB,GAAK,OAAIA,EAAMW,YAEjB,GAAII,IAEC,EAAID,EAAW3B,iBAAiB,UAAU8B,MACzC,SAAAjB,GAAK,OAAIA,EAAMkB,WAQjB,OALAJ,EAAWnB,UAAUC,IAAI,SACrBc,GACFK,EAAcF,aAEhBH,GAAU,MAMTA,O,8BAtFUS,aA0FNrC","file":"67.8f87d6ab30e0064c4d6a.js","sourcesContent":["import { Component } from '@verndale/core';\n\nimport Dropdown from '../../components/dropdown';\nimport DatePicker from '../../components/datepicker';\n\nclass Module extends Component {\n setupDefaults() {\n this.dom = {\n inputs: this.el.querySelectorAll('.custom-form__field input[type=text]'),\n radioGroups: this.el.querySelectorAll('.custom-form__field--radio-group'),\n dropdowns: this.el.querySelectorAll('.custom-form__field select'),\n datepickers: this.el.querySelectorAll(\n '.custom-form__field input[type=date]'\n )\n };\n\n this.el.setAttribute('novalidate', 'novalidate');\n\n //Init dropdowns\n this.dom.dropdowns.forEach(dropdown => {\n dropdown.parentNode.parentNode.classList.add('field_dropdown');\n new Dropdown(dropdown);\n });\n\n //Init datepickers\n this.dom.datepickers.forEach(datepicker => {\n new DatePicker(datepicker);\n });\n }\n\n addListeners() {\n this.dom.inputs.forEach(input => {\n if (input.value) {\n input.parentNode.classList.add('active');\n }\n\n input.addEventListener('focus', e => {\n e.target.parentNode.classList.add('active');\n });\n\n input.addEventListener('blur', e => {\n if (!e.target.value) {\n e.target.parentNode.classList.remove('active');\n }\n });\n });\n\n this.el.addEventListener('submit', this.handleSubmit.bind(this));\n }\n\n async handleSubmit(e) {\n if (!this.validateForm()) {\n e.preventDefault();\n }\n }\n\n validateForm() {\n let isValid = true;\n\n this.dom.inputs.forEach(input => {\n input.parentNode.classList.remove('error');\n if (input.required && !input.value.trim()) {\n input.parentNode.classList.add('error');\n if (isValid) {\n input.focus();\n }\n isValid = false;\n }\n });\n\n this.dom.radioGroups.forEach(radioGroup => {\n radioGroup.classList.remove('error');\n const requiredRadio = [...radioGroup.querySelectorAll('input')].find(\n input => input.required\n );\n if (requiredRadio) {\n if (\n ![...radioGroup.querySelectorAll('input')].some(\n input => input.checked\n )\n ) {\n radioGroup.classList.add('error');\n if (isValid) {\n requiredRadio.focus();\n }\n isValid = false;\n return;\n }\n }\n });\n\n return isValid;\n }\n}\n\nexport default Module;\n"],"sourceRoot":""}