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

react-form-validator-component

Package Overview
Dependencies
Maintainers
3
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-form-validator-component - npm Package Compare versions

Comparing version 1.5.7 to 1.5.8

2

build/lib/index.js

@@ -1,1 +0,1 @@

!function(e,r){for(var t in r)e[t]=r[t]}(exports,function(e){var r={};function t(a){if(r[a])return r[a].exports;var n=r[a]={i:a,l:!1,exports:{}};return e[a].call(n.exports,n,n.exports,t),n.l=!0,n.exports}return t.m=e,t.c=r,t.d=function(e,r,a){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:a})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(t.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)t.d(a,n,function(r){return e[r]}.bind(null,n));return a},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=6)}([function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var a=/^(([^<>()[\]\\.,;:\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,}))$/,n=/^([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})*$/,i=/^[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!!e.match(i)},error:"Please provide a full name"},m={validator:function(e){return!!e.match(a)},error:"Please provide a valid email address"},y={validator:function(e){return!!e.match(n)},error:"Please provide a valid email address, or several emails comma delimited"},b={validator:function(e){return!!e.match(o)},error:"Please provide a valid UK phone number"},g={validator:function(e){return!!e.match(u)},error:"Please provide a valid UK postcode"},O={validator:function(e){return!!e.match(l)},error:"Please provide a UK Sort Code"},A={validator:function(e){return!!e.match(s)},error:"Please provide a valid Swift Code"},j={validator:function(e){return!!e.match(d)},error:"Please provide a valid Swift Code"},P={validator:function(e){return!!e.match(c)},error:"Please provide a valid UK VAT Number"},_={validator:function(e){return!!e.match(f)},error:"Please provide an alphanumeric input"},S={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,r){return e.length===r},error:"Please provide an input of exactly "+length+" characters"},E={validator:function(e,r){return e.length<=r},error:"The maximum length of this input is "+length+" characters"},V={validator:function(e,r){return e.length>=r},error:"The minimum length of this input is "+length+" characters"};r.isRequired={validator:function(e){return!!e},error:"Please provide a value"},r.isEmail=m,r.isEmailArray=y,r.isFullName=h,r.isPhoneNumber=b,r.isPostCode=g,r.isSortCode=O,r.isSwiftCode=A,r.isIban=j,r.isVatNumber=P,r.isAlphaNumeric=_,r.isNumeric=S,r.isUrl=w,r.isLength=z,r.maxLength=E,r.minLength=V},function(e,r,t){"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},function(e,r,t){"use strict";var a=t(1);function n(){}e.exports=function(){function e(e,r,t,n,i,o){if(o!==a){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 r(){return e}e.isRequired=e;var t={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:r,element:e,instanceOf:r,node:e,objectOf:r,oneOf:r,oneOfType:r,shape:r,exact:r};return t.checkPropTypes=n,t.PropTypes=t,t}},function(e,r,t){e.exports=t(2)()},function(e,r){e.exports=require("react")},function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var a=function(){return function(e,r){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,r){var t=[],a=!0,n=!1,i=void 0;try{for(var o,u=e[Symbol.iterator]();!(a=(o=u.next()).done)&&(t.push(o.value),!r||t.length!==r);a=!0);}catch(e){n=!0,i=e}finally{try{!a&&u.return&&u.return()}finally{if(n)throw i}}return t}(e,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),n=function(){function e(e,r){for(var t=0;t<r.length;t++){var a=r[t];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(r,t,a){return t&&e(r.prototype,t),a&&e(r,a),r}}(),i=l(t(4)),o=l(t(3)),u=function(e){if(e&&e.__esModule)return e;var r={};if(null!=e)for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&(r[t]=e[t]);return r.default=e,r}(t(0));function l(e){return e&&e.__esModule?e:{default:e}}function s(e){if(Array.isArray(e)){for(var r=0,t=Array(e.length);r<e.length;r++)t[r]=e[r];return t}return Array.from(e)}function d(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var c=function(e){function r(e){!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,r);var t=function(e,r){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!r||"object"!=typeof r&&"function"!=typeof r?e:r}(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,e));return t.onValidate=function(e,r){t.props.parent.setState(d({},e,r))},t.toArray=function(e){return Object.entries(e).reduce(function(e,r){var t=a(r,2),n=t[0],i=t[1];return e.concat({key:n,value:i})},[])},t.addToStateProperty=function(e,r){t.setState(d({},e,Object.assign(t.state[e],r)))},t.removeError=function(e,r){var a=t.state.errors[e],n=a.indexOf(r);n>-1&&a.splice(n,1),t.addToStateProperty("errors",d({},e,a))},t.removeAllErrors=function(e){t.setState({errors:Object.assign(t.state.errors,d({},e,[]))})},t.updateErrorsForField=function(e,r,a){e?t.removeError(r,a):t.addToStateProperty("errors",d({},r,[].concat(s(new Set([].concat(s(t.state.errors[r]||[]),[a]))))))},t.validateRules=function(e,r,a){return a.reduce(function(a,n){var i=u[n]||n,o=i.validator(r);return t.updateErrorsForField(o,e,i.error),a&&o},!0)},t.validateGroup=function(e,r,a){if(t.state.groupValidation[a]&&Object.entries(t.state.groupValidation[a]).filter(function(r){return!r.includes(e)}).some(function(e){return e.includes(!0)})){var n=t.props.fields[e].rules,i=t.validateRules(e,r,n);return t.setState({groupValidation:Object.assign({},t.state.groupValidation[a],d({},e,i))}),!0}var o=t.props.fields[e].rules,u=t.validateRules(e,r,o),l=t.state.groupValidation;return l[a]=Object.assign({},l[a],d({},e,u)),t.setState({groupValidation:Object.assign({},t.state.groupValidation,l)},function(){return t.setState({validation:Object.assign(t.state.validation,d({},a,Object.values(t.state.groupValidation[a]).some(function(e){return!0===e})))})}),u},t.validateField=function(e,r){var a=t.props.fields[e].required&&"string"==typeof t.props.fields[e].required?t.props.fields[e].required:void 0;if(!a&&!t.props.fields[e].required&&0===r.length)return t.setState({validation:Object.assign(t.state.validation,d({},e,!0))},function(){return t.removeAllErrors(e)}),!0;if(a)return t.validateGroup(e,r,a);var n=t.props.fields[e].rules,i=t.validateRules(e,r,n);return t.setState({validation:Object.assign(t.state.validation,d({},e,i))}),i},t.validateFormAndUpdateState=function(){Object.values(t.props.fields).map(function(e){return e.name}).filter(function(e){return e}).forEach(function(e){var r=document.getElementsByName(e)[0]&&document.getElementsByName(e)[0].value?document.getElementsByName(e)[0].value:"";t.validateFieldAndUpdateState(e,r)})},t.onChange=function(e,r){var a=r||e.target;t.validateFieldAndUpdateState(a.name,a.value)},t.validateFieldsInput=function(){Object.values(t.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 each field (or an empty array for non-validated fields)")})},console.log("props: ",e),t.state={errors:Object.keys(e.fields).reduce(function(e,r){return e[r]=[],e},{}),groupValidation:Object.keys(e.fields).reduce(function(r,t){var a=e.fields[t];return a.required&&"string"==typeof a.required?(r[a.required]=Object.assign({},r[a.required],d({},t,!(a.rules&&a.rules.length>0||a.required))),r):r},{}),validation:Object.keys(e.fields).reduce(function(r,t){var a=e.fields[t];return a.required&&"string"==typeof a.required?(r[a.required]=!1,r):(r[t]=!(a.rules&&a.rules.length>0||a.required),r)},{}),isFormValid:!1},t}return function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function, not "+typeof r);e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),r&&(Object.setPrototypeOf?Object.setPrototypeOf(e,r):e.__proto__=r)}(r,i.default.Component),n(r,[{key:"validateFieldAndUpdateState",value:function(e,r){var t=this.props.fields[e].onValidate||this.props.onValidate||this.onValidate;this.validateField(e,r)?t(e,r):t(e,null),this.setState({isFormValid:Object.values(this.state.validation).every(function(e){return e})})}},{key:"componentDidMount",value:function(){var e=this;this.validateFieldsInput(),Object.values(this.props.fields).forEach(function(r){if(!0===r.required){var t=e.props.fields;t[r.name].rules.push("isRequired"),e.setState({fields:t})}}),this.validateFormAndUpdateState(),this.props.validateOnLoad&&Object.values(this.props.fields).map(function(r){return e.removeAllErrors(r.name)})}},{key:"render",value:function(){var e=this.state,r=e.fields,t=e.errors,a=e.isFormValid,n=e.validation;return this.props.children({isFormValid:a,isFieldValid:n,fields:this.toArray(r),onChange:this.onChange,errors:t})}}]),r}();r.default=c,c.propTypes={parent:o.default.object,children:o.default.func,onValidate:o.default.func,fields:o.default.object,validateOnLoad:o.default.bool},c.defaultProps={validateOnLoad:!0}},function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.Validator=void 0;var a=function(e){return e&&e.__esModule?e:{default:e}}(t(5));r.Validator=a.default}]));
!function(e,r){for(var t in r)e[t]=r[t]}(exports,function(e){var r={};function t(a){if(r[a])return r[a].exports;var n=r[a]={i:a,l:!1,exports:{}};return e[a].call(n.exports,n,n.exports,t),n.l=!0,n.exports}return t.m=e,t.c=r,t.d=function(e,r,a){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:a})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(t.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)t.d(a,n,function(r){return e[r]}.bind(null,n));return a},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=6)}([function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var a=/^(([^<>()[\]\\.,;:\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,}))$/,n=/^([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})*$/,o=/^[a-zA-Z]+(([',. -][a-zA-Z ])?[a-zA-Z]*)*$/,i=/^[+]?(\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!!e.match(o)},error:"Please provide a full name"},m={validator:function(e){return!!e.match(a)},error:"Please provide a valid email address"},y={validator:function(e){return!!e.match(n)},error:"Please provide a valid email address, or several emails comma delimited"},b={validator:function(e){return!!e.match(i)},error:"Please provide a valid UK phone number"},g={validator:function(e){return!!e.match(u)},error:"Please provide a valid UK postcode"},O={validator:function(e){return!!e.match(l)},error:"Please provide a UK Sort Code"},j={validator:function(e){return!!e.match(s)},error:"Please provide a valid Swift Code"},A={validator:function(e){return!!e.match(d)},error:"Please provide a valid Swift Code"},P={validator:function(e){return!!e.match(c)},error:"Please provide a valid UK VAT Number"},_={validator:function(e){return!!e.match(f)},error:"Please provide an alphanumeric input"},S={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,r){return e.length===r},error:"Please provide an input of exactly "+length+" characters"},E={validator:function(e,r){return e.length<=r},error:"The maximum length of this input is "+length+" characters"},V={validator:function(e,r){return e.length>=r},error:"The minimum length of this input is "+length+" characters"};r.isRequired={validator:function(e){return!!e},error:"Please provide a value"},r.isEmail=m,r.isEmailArray=y,r.isFullName=h,r.isPhoneNumber=b,r.isPostCode=g,r.isSortCode=O,r.isSwiftCode=j,r.isIban=A,r.isVatNumber=P,r.isAlphaNumeric=_,r.isNumeric=S,r.isUrl=w,r.isLength=z,r.maxLength=E,r.minLength=V},function(e,r,t){"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},function(e,r,t){"use strict";var a=t(1);function n(){}e.exports=function(){function e(e,r,t,n,o,i){if(i!==a){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 r(){return e}e.isRequired=e;var t={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:r,element:e,instanceOf:r,node:e,objectOf:r,oneOf:r,oneOfType:r,shape:r,exact:r};return t.checkPropTypes=n,t.PropTypes=t,t}},function(e,r,t){e.exports=t(2)()},function(e,r){e.exports=require("react")},function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var a=function(){return function(e,r){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,r){var t=[],a=!0,n=!1,o=void 0;try{for(var i,u=e[Symbol.iterator]();!(a=(i=u.next()).done)&&(t.push(i.value),!r||t.length!==r);a=!0);}catch(e){n=!0,o=e}finally{try{!a&&u.return&&u.return()}finally{if(n)throw o}}return t}(e,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),n=function(){function e(e,r){for(var t=0;t<r.length;t++){var a=r[t];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(r,t,a){return t&&e(r.prototype,t),a&&e(r,a),r}}(),o=l(t(4)),i=l(t(3)),u=function(e){if(e&&e.__esModule)return e;var r={};if(null!=e)for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&(r[t]=e[t]);return r.default=e,r}(t(0));function l(e){return e&&e.__esModule?e:{default:e}}function s(e){if(Array.isArray(e)){for(var r=0,t=Array(e.length);r<e.length;r++)t[r]=e[r];return t}return Array.from(e)}function d(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var c=function(e){function r(e){!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,r);var t=function(e,r){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!r||"object"!=typeof r&&"function"!=typeof r?e:r}(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,e));return t.onValidate=function(e,r){t.props.parent.setState(d({},e,r))},t.toArray=function(e){return console.log("object, ",e),Object.entries(e).reduce(function(e,r){var t=a(r,2),n=t[0],o=t[1];return e.concat({key:n,value:o})},[])},t.addToStateProperty=function(e,r){t.setState(d({},e,Object.assign(t.state[e],r)))},t.removeError=function(e,r){var a=t.state.errors[e],n=a.indexOf(r);n>-1&&a.splice(n,1),t.addToStateProperty("errors",d({},e,a))},t.removeAllErrors=function(e){t.setState({errors:Object.assign(t.state.errors,d({},e,[]))})},t.updateErrorsForField=function(e,r,a){e?t.removeError(r,a):t.addToStateProperty("errors",d({},r,[].concat(s(new Set([].concat(s(t.state.errors[r]||[]),[a]))))))},t.validateRules=function(e,r,a){return a.reduce(function(a,n){var o=u[n]||n,i=o.validator(r);return t.updateErrorsForField(i,e,o.error),a&&i},!0)},t.validateGroup=function(e,r,a){if(t.state.groupValidation[a]&&Object.entries(t.state.groupValidation[a]).filter(function(r){return!r.includes(e)}).some(function(e){return e.includes(!0)})){var n=t.props.fields[e].rules,o=t.validateRules(e,r,n);return t.setState({groupValidation:Object.assign({},t.state.groupValidation[a],d({},e,o))}),!0}var i=t.props.fields[e].rules,u=t.validateRules(e,r,i),l=t.state.groupValidation;return l[a]=Object.assign({},l[a],d({},e,u)),t.setState({groupValidation:Object.assign({},t.state.groupValidation,l)},function(){return t.setState({validation:Object.assign(t.state.validation,d({},a,Object.values(t.state.groupValidation[a]).some(function(e){return!0===e})))})}),u},t.validateField=function(e,r){var a=t.props.fields[e].required&&"string"==typeof t.props.fields[e].required?t.props.fields[e].required:void 0;if(!a&&!t.props.fields[e].required&&0===r.length)return t.setState({validation:Object.assign(t.state.validation,d({},e,!0))},function(){return t.removeAllErrors(e)}),!0;if(a)return t.validateGroup(e,r,a);var n=t.props.fields[e].rules,o=t.validateRules(e,r,n);return t.setState({validation:Object.assign(t.state.validation,d({},e,o))}),o},t.validateFormAndUpdateState=function(){Object.values(t.props.fields).map(function(e){return e.name}).filter(function(e){return e}).forEach(function(e){var r=document.getElementsByName(e)[0]&&document.getElementsByName(e)[0].value?document.getElementsByName(e)[0].value:"";t.validateFieldAndUpdateState(e,r)})},t.onChange=function(e,r){var a=r||e.target;t.validateFieldAndUpdateState(a.name,a.value)},t.validateFieldsInput=function(){Object.values(t.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 each field (or an empty array for non-validated fields)")})},console.log("props: ",e),t.state={errors:Object.keys(e.fields).reduce(function(e,r){return e[r]=[],e},{}),groupValidation:Object.keys(e.fields).reduce(function(r,t){var a=e.fields[t];return a.required&&"string"==typeof a.required?(r[a.required]=Object.assign({},r[a.required],d({},t,!(a.rules&&a.rules.length>0||a.required))),r):r},{}),validation:Object.keys(e.fields).reduce(function(r,t){var a=e.fields[t];return a.required&&"string"==typeof a.required?(r[a.required]=!1,r):(r[t]=!(a.rules&&a.rules.length>0||a.required),r)},{}),isFormValid:!1},t}return function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function, not "+typeof r);e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),r&&(Object.setPrototypeOf?Object.setPrototypeOf(e,r):e.__proto__=r)}(r,o.default.Component),n(r,[{key:"validateFieldAndUpdateState",value:function(e,r){var t=this.props.fields[e].onValidate||this.props.onValidate||this.onValidate;this.validateField(e,r)?t(e,r):t(e,null),this.setState({isFormValid:Object.values(this.state.validation).every(function(e){return e})})}},{key:"componentDidMount",value:function(){var e=this;this.validateFieldsInput(),Object.values(this.props.fields).forEach(function(r){if(!0===r.required){var t=e.props.fields;t[r.name].rules.push("isRequired"),e.setState({fields:t})}}),this.validateFormAndUpdateState(),this.props.validateOnLoad&&Object.values(this.props.fields).map(function(r){return e.removeAllErrors(r.name)})}},{key:"render",value:function(){var e=this.state,r=e.errors,t=e.isFormValid,a=e.validation;return this.props.children({isFormValid:t,isFieldValid:a,fields:this.toArray(this.props.fields),onChange:this.onChange,errors:r})}}]),r}();r.default=c,c.propTypes={parent:i.default.object,children:i.default.func,onValidate:i.default.func,fields:i.default.object,validateOnLoad:i.default.bool},c.defaultProps={validateOnLoad:!0}},function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.Validator=void 0;var a=function(e){return e&&e.__esModule?e:{default:e}}(t(5));r.Validator=a.default}]));
{
"name": "react-form-validator-component",
"version": "1.5.7",
"version": "1.5.8",
"main": "build/lib/index.js",

@@ -5,0 +5,0 @@ "repository": "git@github.com:JDLT-Ltd/react-form-validator-component.git",

@@ -46,2 +46,3 @@ import React from 'react'

toArray = object => {
console.log('object, ', object)
return Object.entries(object).reduce((accumulator, [key, value]) => {

@@ -212,7 +213,7 @@ return accumulator.concat({

render() {
const { fields, errors, isFormValid, validation } = this.state
const { errors, isFormValid, validation } = this.state
return this.props.children({
isFormValid,
isFieldValid: validation,
fields: this.toArray(fields),
fields: this.toArray(this.props.fields),
onChange: this.onChange,

@@ -219,0 +220,0 @@ errors

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