react-form-validator-component
Advanced tools
Comparing version 1.7.7 to 1.7.8
@@ -1,1 +0,1 @@ | ||
!function(e,t){for(var r in t)e[r]=t[r]}(exports,function(e){var t={};function r(i){if(t[i])return t[i].exports;var a=t[i]={i:i,l:!1,exports:{}};return e[i].call(a.exports,a,a.exports,r),a.l=!0,a.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 a in e)r.d(i,a,function(t){return e[t]}.bind(null,a));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=8)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var r=[],i=!0,a=!1,n=void 0;try{for(var o,u=e[Symbol.iterator]();!(i=(o=u.next()).done)&&(r.push(o.value),!t||r.length!==t);i=!0);}catch(e){a=!0,n=e}finally{try{!i&&u.return&&u.return()}finally{if(a)throw n}}return r}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();t.default=function(e){return Object.entries(e).reduce(function(e,t){var r=i(t,2),a=r[0],n=r[1];return e.concat({key:a,value:n})},[])}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t,r){r.setState(function(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}({},e,Object.assign(r.state[e],t)),function(){"validation"===e&&r.setState({isFormValid:Object.values(r.state.validation).every(function(e){return!0===e})})})}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,a=/^([a-zA-Z0-9_\-.]+)@([a-zA-Z0-9_\-.]+)\.([a-zA-Z]{2,5}){1,25}(,[ ]{0,1}([a-zA-Z0-9_\-.]+)@([a-zA-Z0-9_\-.]+)\.([a-zA-Z]{2,5}){1,25})*$/,n=/^[a-zA-Z]+(([',. -][a-zA-Z ])?[a-zA-Z]*)*$/,o=/^[+]?(\d{1,3})\s?(\d{10})$/,u=/^(([A-Za-z0-9]{2,4})\s?([A-Za-z0-9]{1,5})?)?$/,l=/^(\d{2}(\s|[-])\d{2}(\s|[-])\d{2}$)|\d{6}|^$/,s=/^((([A-Za-z]{6}[0-9A-Za-z]{2})|([A-Za-z]{4}(\s|-)?[A-Za-z]{2}(\s|-)?[0-9A-Za-z]{2}))[0-9A-Za-z]{3}?$)|^$/,d=/^([0-9A-Za-z]{4}\s?){4,6}([0-9A-Za-z]{1,4}|[0-9A-Za-z]{4}\s?[0-9A-Za-z]{1|4})?$/,c=/^\d{8,15}$/,f=/^[A-Z0-9a-z\-/\s]+$/i,p=/^-?\d*[.]?\d+$/,v=/^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([-.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/g,h={validator:function(e){return!!(Array.isArray(e)&&e.length>0||!1===e||e&&!Array.isArray(e))},error:"Please provide a value."},y={validator:function(e){return!!e.match(n)},error:"Please provide a full name"},m={validator:function(e){return!!e.match(i)},error:"Please provide a valid email address"},b={validator:function(e){return!!e.match(a)},error:"Please provide a valid email address, or several emails comma delimited"},g={validator:function(e){return!!e.match(o)},error:"Please provide a valid UK phone number"},O={validator:function(e){return!!e.match(u)},error:"Please provide a valid UK postcode"},j={validator:function(e){return!!e.match(l)},error:"Please provide a UK Sort Code"},P={validator:function(e){return!!e.match(s)},error:"Please provide a valid Swift Code"},V={validator:function(e){return!!e.match(d)},error:"Please provide a valid Swift Code"},A={validator:function(e){return!!e.match(c)},error:"Please provide a valid UK VAT Number"},S={validator:function(e){return!!e.match(f)},error:"Please provide an alphanumeric input"},_={validator:function(e){return"number"==typeof e||!!e.match(p)},error:"Please provide an numeric input"},w={validator:function(e){return!!e.match(v)},error:"Please provide a valid URL"},z={validator:function(e,t){return e.length===t},error:"Please provide an input of exactly "+length+" characters"},E={validator:function(e,t){return e.length<=t},error:"The maximum length of this input is "+length+" characters"},F={validator:function(e,t){return e.length>=t},error:"The minimum length of this input is "+length+" characters"};t.isRequired=h,t.isEmail=m,t.isEmailArray=b,t.isFullName=y,t.isPhoneNumber=g,t.isPostCode=O,t.isSortCode=j,t.isSwiftCode=P,t.isIban=V,t.isVatNumber=A,t.isAlphaNumeric=S,t.isNumeric=_,t.isUrl=w,t.isLength=z,t.maxLength=E,t.minLength=F},function(e,t,r){"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},function(e,t,r){"use strict";var i=r(3);function a(){}e.exports=function(){function e(e,t,r,a,n,o){if(o!==i){var u=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw u.name="Invariant Violation",u}}function t(){return e}e.isRequired=e;var r={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t};return r.checkPropTypes=a,r.PropTypes=r,r}},function(e,t,r){e.exports=r(4)()},function(e,t){e.exports=require("react")},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(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)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),a=s(r(6)),n=s(r(5)),o=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}(r(2)),u=s(r(1)),l=s(r(0));function s(e){return e&&e.__esModule?e:{default:e}}function d(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)}function c(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(e){function t(e){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var i=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return i.onValidate=function(e,t){i.props.parent.setState(c({},e,t))},i.removeError=function(e,t){var r=i.state.errors[e],a=r.indexOf(t);a>-1&&r.splice(a,1),(0,u.default)("errors",c({},e,r),i)},i.removeAllErrorMessages=function(e){i.setState({errors:Object.assign(i.state.errors,c({},e,[]))})},i.updateErrorsForField=function(e,t,r){e?i.removeError(t,r):(0,u.default)("errors",c({},t,[].concat(d(new Set([].concat(d(i.state.errors[t]||[]),[r]))))),i)},i.validateRules=function(e,t,r){return r.reduce(function(r,a){var n=o[a]||a,u=n.validator(t);return i.updateErrorsForField(u,e,n.error),r&&u},!0)},i.validateGroup=function(e,t,r){if(i.state.groupValidation[r]&&Object.entries(i.state.groupValidation[r]).filter(function(t){return!t.includes(e)}).some(function(e){return e.includes(!0)})){var a,n,o=i.props.fields[e].rules,u=i.validateRules(e,t,o),l=i.state.groupValidation;l[r]=!t||Array.isArray(t)&&0===t.length||u?Object.assign({},i.state.groupValidation[r],(c(a={},e,u),c(a,"invalidValuePresent",!1),a)):Object.assign({},i.state.groupValidation[r],(c(n={},e,u),c(n,"invalidValuePresent",!0),n));var s=Object.assign({},i.state.validation,c({},r,Object.values(Object.assign({},l[r],{invalidValuePresent:!1})).some(function(e){return!0===e})&&!l[r].invalidValuePresent));return i.setState({groupValidation:l},function(){return i.setState({validation:s,isFormValid:Object.values(s).every(function(e){return!0===e})})}),u}var d=i.props.fields[e].rules,f=i.validateRules(e,t,d),p=i.state.groupValidation;return p[r]=Object.assign({},p[r],c({},e,f)),i.setState({groupValidation:Object.assign({},i.state.groupValidation,p)},function(){return i.setState({validation:Object.assign(i.state.validation,c({},r,Object.values(Object.assign({},i.state.groupValidation[r],{invalidValuePresent:!1})).some(function(e){return!0===e})&&!i.state.groupValidation[r].invalidValuePresent))})}),f},i.validateField=function(e,t){var r=i.props.fields[e],a=i.props.fields[e].required&&"string"==typeof i.props.fields[e].required?i.props.fields[e].required:void 0;if(!a&&!r.required&&0===t.length)return(0,u.default)("validation",c({},e,!0),i),!0;if(a)return i.validateGroup(e,t,a);var n=r.rules,o=i.validateRules(e,t,n);return(0,u.default)("validation",c({},e,o),i),o},i.initialValidation=function(e){return function(){var t=e.apply(this,arguments);return new Promise(function(e,r){return function i(a,n){try{var o=t[a](n),u=o.value}catch(e){return void r(e)}if(!o.done)return Promise.resolve(u).then(function(e){i("next",e)},function(e){i("throw",e)});e(u)}("next")})}}(regeneratorRuntime.mark(function e(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:Object.values(i.props.fields).filter(function(e){return e}).forEach(function(e){var t=(document.getElementsByName(e.name)[0]||{}).value,r=e.defaultValue||t;i.validateFieldAndUpdateState(e.name,r)});case 2:case"end":return e.stop()}},e,r)})),i.onChange=function(e,t){var r=t||e.target;i.validateFieldAndUpdateState(r.name,r.value)},i.validateFieldsProp=function(){Object.values(i.props.fields).forEach(function(e){if(!e.name)throw new Error("Please provide a name value for all of your fields");if(!e.rules)throw new Error("Please provide a rules array for field "+e.name+" (or an empty array for non-validated fields)")})},i.state={errors:i.initialiseStateErrors(e.fields),groupValidation:i.initialiseStateGroupValidation(e.fields),validation:i.initialiseStateFieldValidation(e.fields),isFormValid:!1,validatorInput:{}},i}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,a.default.Component),i(t,[{key:"componentDidMount",value:function(){var e=this;this.validateFieldsProp(),this.addRequiredRuleToFields(),this.initialValidation(),this.props.validateOnLoad&&Object.values(this.props.fields).forEach(function(t){return e.removeAllErrorMessages(t.name)})}},{key:"initialiseStateErrors",value:function(e){return Object.keys(e).reduce(function(e,t){return e[t]=[],e},{})}},{key:"initialiseStateGroupValidation",value:function(e){return Object.keys(e).reduce(function(t,r){var i=e[r];return i.required&&"string"==typeof i.required?(t[i.required]=Object.assign({},t[i.required],c({},r,!(i.rules&&i.rules.length>0||i.required))),t):t},{})}},{key:"initialiseStateFieldValidation",value:function(e){return Object.keys(e).reduce(function(t,r){var i=e[r];return i.required&&"string"==typeof i.required?(t[i.required]=!1,t):(t[r]=!(i.rules&&i.rules.length>0||i.required),t)},{})}},{key:"componentDidUpdate",value:function(e){var t=this.props;JSON.stringify(t.fields)!==JSON.stringify(e.fields)&&this.setState({fields:t.fields,errors:this.initialiseStateErrors(t.fields),groupValidation:this.initialiseStateGroupValidation(t.fields),validation:this.initialiseStateFieldValidation(t.fields),isFormValid:Object.values(this.initialiseStateFieldValidation(t.fields)).every(function(e){return!0===e})})}},{key:"validateFieldAndUpdateState",value:function(e,t){var r=this.props.fields[e].onValidate||this.props.onValidate||this.onValidate;if(this.validateField(e,t))r(e,t);else{if(null===this.state.validation[e])return null;r(e,null)}this.props.returnInput&&((0,u.default)("validatorInput",c({},e,t),this),this.props.parent.setState({validatorInput:this.state.validatorInput}))}},{key:"addRequiredRuleToFields",value:function(){var e=this;Object.values(this.props.fields).forEach(function(t){if(!0===t.required||"string"==typeof t.required){var r=e.props.fields;r[t.name].rules.push("isRequired"),e.setState({fields:r})}})}},{key:"render",value:function(){var e=this.state,t=e.errors,r=e.isFormValid,i=e.validation,a=e.groupValidation;return this.props.children({isFormValid:r,isFieldValid:Object.assign.apply(Object,[{},i].concat(d(Object.values(a)))),fields:(0,l.default)(this.props.fields||{}),onChange:this.onChange,errors:t})}}]),t}();t.default=f,f.propTypes={parent:n.default.object,children:n.default.func,onValidate:n.default.func,fields:n.default.object,validateOnLoad:n.default.bool,returnInput:n.default.bool},f.defaultProps={validateOnLoad:!0,returnInput:!1}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Validator=void 0;var i=function(e){return e&&e.__esModule?e:{default:e}}(r(7));t.Validator=i.default}])); | ||
!function(e,t){for(var r in t)e[r]=t[r]}(exports,function(e){var t={};function r(i){if(t[i])return t[i].exports;var a=t[i]={i:i,l:!1,exports:{}};return e[i].call(a.exports,a,a.exports,r),a.l=!0,a.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 a in e)r.d(i,a,function(t){return e[t]}.bind(null,a));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=8)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var r=[],i=!0,a=!1,n=void 0;try{for(var o,u=e[Symbol.iterator]();!(i=(o=u.next()).done)&&(r.push(o.value),!t||r.length!==t);i=!0);}catch(e){a=!0,n=e}finally{try{!i&&u.return&&u.return()}finally{if(a)throw n}}return r}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();t.default=function(e){return Object.entries(e).reduce(function(e,t){var r=i(t,2),a=r[0],n=r[1];return e.concat({key:a,value:n})},[])}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t,r){r.setState(function(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}({},e,Object.assign(r.state[e],t)),function(){"validation"===e&&r.setState({isFormValid:Object.values(r.state.validation).every(function(e){return!0===e})})})}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,a=/^(.{1,})@(.{2,})/,n=/^[a-zA-Z]+(([',. -][a-zA-Z ])?[a-zA-Z]*)*$/,o=/^[+]?(\d{1,3})\s?(\d{10})$/,u=/^(([A-Za-z0-9]{2,4})\s?([A-Za-z0-9]{1,5})?)?$/,l=/^(\d{2}(\s|[-])\d{2}(\s|[-])\d{2}$)|\d{6}|^$/,s=/^((([A-Za-z]{6}[0-9A-Za-z]{2})|([A-Za-z]{4}(\s|-)?[A-Za-z]{2}(\s|-)?[0-9A-Za-z]{2}))[0-9A-Za-z]{3}?$)|^$/,d=/^([0-9A-Za-z]{4}\s?){4,6}([0-9A-Za-z]{1,4}|[0-9A-Za-z]{4}\s?[0-9A-Za-z]{1|4})?$/,c=/^\d{8,15}$/,f=/^[A-Z0-9a-z\-/\s]+$/i,p=/^-?\d*[.]?\d+$/,v=/^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([-.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/g,h={validator:function(e){return!!(Array.isArray(e)&&e.length>0||!1===e||e&&!Array.isArray(e))},error:"Please provide a value."},y={validator:function(e){return!!e.match(n)},error:"Please provide a full name"},m={validator:function(e){return!!e.match(i)},error:"Please provide a valid email address"},b={validator:function(e){return!!e.match(a)},error:"Please provide a valid email address, or several emails comma delimited"},g={validator:function(e){return!!e.match(o)},error:"Please provide a valid UK phone number"},O={validator:function(e){return!!e.match(u)},error:"Please provide a valid UK postcode"},j={validator:function(e){return!!e.match(l)},error:"Please provide a UK Sort Code"},P={validator:function(e){return!!e.match(s)},error:"Please provide a valid Swift Code"},V={validator:function(e){return!!e.match(d)},error:"Please provide a valid Swift Code"},S={validator:function(e){return!!e.match(c)},error:"Please provide a valid UK VAT Number"},A={validator:function(e){return!!e.match(f)},error:"Please provide an alphanumeric input"},_={validator:function(e){return"number"==typeof e||!!e.match(p)},error:"Please provide an numeric input"},w={validator:function(e){return!!e.match(v)},error:"Please provide a valid URL"},E={validator:function(e,t){return e.length===t},error:"Please provide an input of exactly "+length+" characters"},F={validator:function(e,t){return e.length<=t},error:"The maximum length of this input is "+length+" characters"},q={validator:function(e,t){return e.length>=t},error:"The minimum length of this input is "+length+" characters"};t.isRequired=h,t.isEmail=m,t.isEmailArray=b,t.isFullName=y,t.isPhoneNumber=g,t.isPostCode=O,t.isSortCode=j,t.isSwiftCode=P,t.isIban=V,t.isVatNumber=S,t.isAlphaNumeric=A,t.isNumeric=_,t.isUrl=w,t.isLength=E,t.maxLength=F,t.minLength=q},function(e,t,r){"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},function(e,t,r){"use strict";var i=r(3);function a(){}e.exports=function(){function e(e,t,r,a,n,o){if(o!==i){var u=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw u.name="Invariant Violation",u}}function t(){return e}e.isRequired=e;var r={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t};return r.checkPropTypes=a,r.PropTypes=r,r}},function(e,t,r){e.exports=r(4)()},function(e,t){e.exports=require("react")},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(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)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),a=s(r(6)),n=s(r(5)),o=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}(r(2)),u=s(r(1)),l=s(r(0));function s(e){return e&&e.__esModule?e:{default:e}}function d(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)}function c(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(e){function t(e){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var i=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return i.onValidate=function(e,t){i.props.parent.setState(c({},e,t))},i.removeError=function(e,t){var r=i.state.errors[e],a=r.indexOf(t);a>-1&&r.splice(a,1),(0,u.default)("errors",c({},e,r),i)},i.removeAllErrorMessages=function(e){i.setState({errors:Object.assign(i.state.errors,c({},e,[]))})},i.updateErrorsForField=function(e,t,r){e?i.removeError(t,r):(0,u.default)("errors",c({},t,[].concat(d(new Set([].concat(d(i.state.errors[t]||[]),[r]))))),i)},i.validateRules=function(e,t,r){return r.reduce(function(r,a){var n=o[a]||a,u=n.validator(t);return i.updateErrorsForField(u,e,n.error),r&&u},!0)},i.validateGroup=function(e,t,r){if(i.state.groupValidation[r]&&Object.entries(i.state.groupValidation[r]).filter(function(t){return!t.includes(e)}).some(function(e){return e.includes(!0)})){var a,n,o=i.props.fields[e].rules,u=i.validateRules(e,t,o),l=i.state.groupValidation;l[r]=!t||Array.isArray(t)&&0===t.length||u?Object.assign({},i.state.groupValidation[r],(c(a={},e,u),c(a,"invalidValuePresent",!1),a)):Object.assign({},i.state.groupValidation[r],(c(n={},e,u),c(n,"invalidValuePresent",!0),n));var s=Object.assign({},i.state.validation,c({},r,Object.values(Object.assign({},l[r],{invalidValuePresent:!1})).some(function(e){return!0===e})&&!l[r].invalidValuePresent));return i.setState({groupValidation:l},function(){return i.setState({validation:s,isFormValid:Object.values(s).every(function(e){return!0===e})})}),u}var d=i.props.fields[e].rules,f=i.validateRules(e,t,d),p=i.state.groupValidation;return p[r]=Object.assign({},p[r],c({},e,f)),i.setState({groupValidation:Object.assign({},i.state.groupValidation,p)},function(){return i.setState({validation:Object.assign(i.state.validation,c({},r,Object.values(Object.assign({},i.state.groupValidation[r],{invalidValuePresent:!1})).some(function(e){return!0===e})&&!i.state.groupValidation[r].invalidValuePresent))})}),f},i.validateField=function(e,t){var r=i.props.fields[e],a=i.props.fields[e].required&&"string"==typeof i.props.fields[e].required?i.props.fields[e].required:void 0;if(!a&&!r.required&&0===t.length)return(0,u.default)("validation",c({},e,!0),i),!0;if(a)return i.validateGroup(e,t,a);var n=r.rules,o=i.validateRules(e,t,n);return(0,u.default)("validation",c({},e,o),i),o},i.initialValidation=function(e){return function(){var t=e.apply(this,arguments);return new Promise(function(e,r){return function i(a,n){try{var o=t[a](n),u=o.value}catch(e){return void r(e)}if(!o.done)return Promise.resolve(u).then(function(e){i("next",e)},function(e){i("throw",e)});e(u)}("next")})}}(regeneratorRuntime.mark(function e(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:Object.values(i.props.fields).filter(function(e){return e}).forEach(function(e){var t=(document.getElementsByName(e.name)[0]||{}).value,r=e.defaultValue||t;i.validateFieldAndUpdateState(e.name,r)});case 2:case"end":return e.stop()}},e,r)})),i.onChange=function(e,t){var r=t||e.target;i.validateFieldAndUpdateState(r.name,r.value)},i.validateFieldsProp=function(){Object.values(i.props.fields).forEach(function(e){if(!e.name)throw new Error("Please provide a name value for all of your fields");if(!e.rules)throw new Error("Please provide a rules array for field "+e.name+" (or an empty array for non-validated fields)")})},i.state={errors:i.initialiseStateErrors(e.fields),groupValidation:i.initialiseStateGroupValidation(e.fields),validation:i.initialiseStateFieldValidation(e.fields),isFormValid:!1,validatorInput:{}},i}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,a.default.Component),i(t,[{key:"componentDidMount",value:function(){var e=this;this.validateFieldsProp(),this.addRequiredRuleToFields(),this.initialValidation(),this.props.validateOnLoad&&Object.values(this.props.fields).forEach(function(t){return e.removeAllErrorMessages(t.name)})}},{key:"initialiseStateErrors",value:function(e){return Object.keys(e).reduce(function(e,t){return e[t]=[],e},{})}},{key:"initialiseStateGroupValidation",value:function(e){return Object.keys(e).reduce(function(t,r){var i=e[r];return i.required&&"string"==typeof i.required?(t[i.required]=Object.assign({},t[i.required],c({},r,!(i.rules&&i.rules.length>0||i.required))),t):t},{})}},{key:"initialiseStateFieldValidation",value:function(e){return Object.keys(e).reduce(function(t,r){var i=e[r];return i.required&&"string"==typeof i.required?(t[i.required]=!1,t):(t[r]=!(i.rules&&i.rules.length>0||i.required),t)},{})}},{key:"componentDidUpdate",value:function(e){var t=this.props;JSON.stringify(t.fields)!==JSON.stringify(e.fields)&&this.setState({fields:t.fields,errors:this.initialiseStateErrors(t.fields),groupValidation:this.initialiseStateGroupValidation(t.fields),validation:this.initialiseStateFieldValidation(t.fields),isFormValid:Object.values(this.initialiseStateFieldValidation(t.fields)).every(function(e){return!0===e})})}},{key:"validateFieldAndUpdateState",value:function(e,t){var r=this.props.fields[e].onValidate||this.props.onValidate||this.onValidate;if(this.validateField(e,t))r(e,t);else{if(null===this.state.validation[e])return null;r(e,null)}this.props.returnInput&&((0,u.default)("validatorInput",c({},e,t),this),this.props.parent.setState({validatorInput:this.state.validatorInput}))}},{key:"addRequiredRuleToFields",value:function(){var e=this;Object.values(this.props.fields).forEach(function(t){if(!0===t.required||"string"==typeof t.required){var r=e.props.fields;r[t.name].rules.push("isRequired"),e.setState({fields:r})}})}},{key:"render",value:function(){var e=this.state,t=e.errors,r=e.isFormValid,i=e.validation,a=e.groupValidation;return this.props.children({isFormValid:r,isFieldValid:Object.assign.apply(Object,[{},i].concat(d(Object.values(a)))),fields:(0,l.default)(this.props.fields||{}),onChange:this.onChange,errors:t})}}]),t}();t.default=f,f.propTypes={parent:n.default.object,children:n.default.func,onValidate:n.default.func,fields:n.default.object,validateOnLoad:n.default.bool,returnInput:n.default.bool},f.defaultProps={validateOnLoad:!0,returnInput:!1}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Validator=void 0;var i=function(e){return e&&e.__esModule?e:{default:e}}(r(7));t.Validator=i.default}])); |
{ | ||
"name": "react-form-validator-component", | ||
"version": "1.7.7", | ||
"version": "1.7.8", | ||
"main": "build/lib/index.js", | ||
@@ -5,0 +5,0 @@ "repository": "git@github.com:JDLT-Ltd/react-form-validator-component.git", |
const emailRegex = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ | ||
const emailArrayRegex = /^([a-zA-Z0-9_\-.]+)@([a-zA-Z0-9_\-.]+)\.([a-zA-Z]{2,5}){1,25}(,[ ]{0,1}([a-zA-Z0-9_\-.]+)@([a-zA-Z0-9_\-.]+)\.([a-zA-Z]{2,5}){1,25})*$/ | ||
const emailArrayRegex = /^(.{1,})@(.{2,})/ | ||
const nameRegex = /^[a-zA-Z]+(([',. -][a-zA-Z ])?[a-zA-Z]*)*$/ | ||
@@ -4,0 +4,0 @@ const phoneNumberRegex = /^[+]?(\d{1,3})\s?(\d{10})$/ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
330637