text: !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.SimpleVal=t():e.SimpleVal=t()}(window,function(){return function(e){var t={};function r(i){if(t[i])return t[i].exports;var n=t[i]={i:i,l:!1,exports:{}};return e[i].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=e,r.c=t,r.d=function(e,t,i){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(r.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)r.d(i,n,function(t){return e[t]}.bind(null,n));return i},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";r.r(t);var i=function(e,t,r){return"min"===e?t.length>=r:"max"===e?t.length<=r:void 0},n=function(e,t){return t.test(e)},o=function(e){return n(e,/^[^\D]\d{0,9}((\.|,)\d{1,})?$/)},a=function(e){return n(e,/[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/)};function s(e){return(s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function c(e,t,r){return t&&u(e.prototype,t),r&&u(e,r),e}function d(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var f=function(){function e(t){var r=this,u=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},c=u.validators,f=void 0===c?{}:c,h=u.required,v=void 0!==h&&h,y=u.touched,p=void 0!==y&&y,m=u.ignoreDefaults,b=void 0!==m&&m,g=u.validateAutomatically,C=void 0===g||g,w=u.errorClass,O=u.dirtyClass,S=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;l(this,e),d(this,"onChangeHandler",function(e){r.value=e.target.value.trim(),r.touched||(r.touched=!0),r.validateAutomatically&&r.validate(),r.updateClasses(),r.cb&&r.cb()}),d(this,"updateClasses",function(){r.touched?r.el.classList.add(r.dirtyClass):r.el.classList.remove(r.dirtyClass),r.valid?r.el.classList.remove(r.errorClass):r.el.classList.add(r.errorClass)}),d(this,"defaultValidations",function(){var e=!0;switch(r.type){case"email":return e=a(r.value);default:return e}}),d(this,"customValidations",function(e){var t=e;for(var a in r.validators){var s=r.validators[a];switch(a){case"minLength":t=i("min",r.value,s);break;case"maxLength":t=i("max",r.value,s);break;case"numerical":t=o(r.value);break;case"regex":t=n(r.value,s);default:console.warn("Validator ".concat(a," unavailable."))}if(!t)return t}return t}),d(this,"validate",function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(!r.error){var t=!0;r.ignoreDefaults||(t=r.defaultValidations()),r.type.includes("select")||"checkbox"===r.type||(t=r.customValidations(t)),(r.required&&!r.touched||r.required&&r.touched&&""===r.value||"checkbox"===r.type&&!r.el.checked)&&(t=!1),r.valid=t,e&&r.updateClasses()}}),d(this,"resetState",function(){r.el.value="",r.value="",r.valid=!0,r.touched=!1,r.updateClasses()}),this.error=null;try{if("string"!=typeof t)throw"Error: form field selector should be string - '".concat(s(t),"' passed.");if(""===t.trim())throw"Error: empty form field selector passed.";if(this.el=document.querySelector(t),!this.el)throw"Error: element '".concat(t,"' does not exist.");this.name=this.el.getAttribute("name"),this.el.addEventListener("input",this.onChangeHandler),this.el.addEventListener("change",this.onChangeHandler),this.type=this.el.type,this.value=this.el.value,this.valid=!0,this.validators=f,this.required=v,this.touched=p,this.ignoreDefaults=b,this.validateAutomatically=C,this.errorClass=w,this.dirtyClass=O,this.cb=S}catch(e){this.error=e,console.error(this.error)}}return c(e,[{key:"isValid",get:function(){return this.touched&&this.valid||!this.touched&&!this.required}}]),e}(),h=function(){function e(t){var r=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=i.required,o=void 0!==n&&n,a=i.touched,u=void 0!==a&&a,c=i.validateAutomatically,f=void 0===c||c,h=i.errorClass,v=i.dirtyClass,y=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;l(this,e),d(this,"onChangeHandler",function(e){r.value=r.checked,r.touched||(r.touched=!0),r.validateAutomatically&&r.validate(),r.updateClasses(),r.cb&&r.cb()}),d(this,"updateClasses",function(){r.el.forEach(function(e){return e.classList.remove(r.dirtyClass)});var e=document.querySelector('input[name="'.concat(r.name,'"]:checked'));e&&e.classList.add(r.dirtyClass),r.valid?r.el.forEach(function(e){return e.classList.remove(r.errorClass)}):r.el.forEach(function(e){return e.classList.add(r.errorClass)})}),d(this,"validate",function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];r.valid=!(!r.checked&&r.required),e&&r.updateClasses()}),this.error=null;try{if("string"!=typeof t)throw"Error: form field selector should be string - ".concat(s(t)," passed.");if(""===t.trim())throw"Error: empty form field selector passed.";if(this.el=document.getElementsByName(t),this.el.length<1)throw"Error: passed '".concat(t,"' is not correct radio field name.");this.name=this.el[0].getAttribute("name");var p=!0,m=!1,b=void 0;try{for(var g,C=this.el[Symbol.iterator]();!(p=(g=C.next()).done);p=!0){g.value.addEventListener("change",this.onChangeHandler)}}catch(e){m=!0,b=e}finally{try{p||null==C.return||C.return()}finally{if(m)throw b}}this.type="radio",this.value=this.checked,this.valid=!0,this.required=o,this.touched=u,this.validateAutomatically=f,this.errorClass=h,this.dirtyClass=v,this.cb=y}catch(e){this.error=e,console.error(this.error)}}return c(e,[{key:"checked",get:function(){var e=document.querySelector('input[name="'.concat(this.name,'"]:checked'));return e?e.value:null}},{key:"isValid",get:function(){return this.touched&&this.checked||!this.required}}]),e}(),v=f,y=function(e){if(!e)return null;for(var t=e;"."===t.charAt(0);)t=t.substr(1);return t};function p(e,t){var r=Object.keys(e);return Object.getOwnPropertySymbols&&r.push.apply(r,Object.getOwnPropertySymbols(e)),t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r}function m(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?p(r,!0).forEach(function(t){g(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):p(r).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function b(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function g(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var C=function(){function e(){var t=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=r.fields,n=r.submitBtn,o=void 0===n?null:n,a=r.errorClass,s=r.dirtyClass;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),g(this,"validateFieldsConfig",function(e){return!(!e||e.length<1)}),g(this,"createFields",function(){return t.fieldOptions.map(function(e){var r=m({},e.options,{errorClass:t.errorClass,dirtyClass:t.dirtyClass});return e.options&&"radio"===e.options.type?new h(e.selector,r,t.fieldChangeHandler):new v(e.selector,r,t.fieldChangeHandler)})}),g(this,"validate",function(){return t.valid=t.fields.every(function(e){return e.isValid})}),g(this,"forceFieldValidation",function(){return t.fields.forEach(function(e){return e.validate(!0)})}),g(this,"updateClasses",function(){t.submitBtn&&(t.valid?t.submitBtn.classList.remove(t.disabledClass):t.submitBtn.classList.add(t.disabledClass))}),g(this,"fieldChangeHandler",function(){t.validate(),t.updateClasses()}),g(this,"submitHandler",function(e){e.preventDefault(),t.valid&&t.onSubmit(t.fieldValues)}),g(this,"resetState",function(){t.valid=!1,t.fields.forEach(function(e){return e.resetState()})}),this.error=null;try{if(!this.validateFieldsConfig(i))throw"Error: no fields passed to form constructor.";this.fieldOptions=i,this.errorClass=y(a)||"error",this.dirtyClass=y(s)||"dirty",this.fields=this.createFields(),o&&(this.submitBtn=document.querySelector(o.selector),this.submitBtn.addEventListener("click",this.submitHandler),this.onSubmit=o.onSubmit||function(){return console.warn('Form config: No "submitHandler" callback option passed in your Submit button options.')},this.disabledClass=y(o.disabledClass)||"disabled"),this.valid=!1}catch(e){this.error=e,console.error(this.error)}}var t,r,i;return t=e,(r=[{key:"fieldValues",get:function(){var e={},t=!0,r=!1,i=void 0;try{for(var n,o=this.fields[Symbol.iterator]();!(t=(n=o.next()).done);t=!0){var a=n.value;e=m({},e,g({},a.name,a.value))}}catch(e){r=!0,i=e}finally{try{t||null==o.return||o.return()}finally{if(r)throw i}}return e}}])&&b(t.prototype,r),i&&b(t,i),e}();t.default=C}]).default});
  //# sourceMappingURL=simpleval.dist.js.map