react-form-validator-component
Advanced tools
Comparing version 1.5.5 to 1.5.6
{ | ||
"name": "react-form-validator-component", | ||
"version": "1.5.5", | ||
"version": "1.5.6", | ||
"main": "build/lib/index.js", | ||
@@ -5,0 +5,0 @@ "repository": "git@github.com:JDLT-Ltd/react-form-validator-component.git", |
@@ -20,3 +20,3 @@ import React from 'react' | ||
this.state = {} | ||
this.state = { one: 1 } | ||
} | ||
@@ -54,3 +54,4 @@ | ||
<Header as="h2">Basic Validation</Header> | ||
<Validator fields={this.fields} parent={this}> | ||
<button onClick={() => this.setState({ one: this.state.one + 1 })}>clicky click</button> | ||
<Validator test={this.state.one} fields={this.fields} parent={this}> | ||
{({ isFormValid, onChange, errors }) => { | ||
@@ -57,0 +58,0 @@ return ( |
@@ -8,5 +8,4 @@ import React from 'react' | ||
super(props) | ||
console.log('props: ', props) | ||
this.state = { | ||
fields: props.fields, | ||
errors: Object.keys(props.fields).reduce((accumulator, currentValue) => { | ||
@@ -101,3 +100,3 @@ accumulator[currentValue] = [] | ||
) { | ||
const fieldRules = this.state.fields[fieldName].rules | ||
const fieldRules = this.props.fields[fieldName].rules | ||
const isFieldValid = this.validateRules(fieldName, fieldValue, fieldRules) | ||
@@ -111,3 +110,3 @@ | ||
// check if this field is valid | ||
const fieldRules = this.state.fields[fieldName].rules | ||
const fieldRules = this.props.fields[fieldName].rules | ||
const isFieldValid = this.validateRules(fieldName, fieldValue, fieldRules) | ||
@@ -136,7 +135,7 @@ | ||
const groupName = | ||
this.state.fields[fieldName].required && typeof this.state.fields[fieldName].required === 'string' | ||
? this.state.fields[fieldName].required | ||
this.props.fields[fieldName].required && typeof this.props.fields[fieldName].required === 'string' | ||
? this.props.fields[fieldName].required | ||
: undefined | ||
// ensure that empty non-required fields pass validation and don't throw errors | ||
if (!groupName && !this.state.fields[fieldName].required && fieldValue.length === 0) { | ||
if (!groupName && !this.props.fields[fieldName].required && fieldValue.length === 0) { | ||
this.setState( | ||
@@ -154,3 +153,3 @@ { | ||
// standard validation | ||
const fieldRules = this.state.fields[fieldName].rules | ||
const fieldRules = this.props.fields[fieldName].rules | ||
const isFieldValid = this.validateRules(fieldName, fieldValue, fieldRules) | ||
@@ -164,4 +163,3 @@ this.setState({ | ||
validateFieldAndUpdateState(fieldName, fieldValue) { | ||
console.log('fields: ', this.state.fields, 'fieldName: ', fieldName, 'fieldValue: ', fieldValue) | ||
const onValidate = this.state.fields[fieldName].onValidate || this.props.onValidate || this.onValidate | ||
const onValidate = this.props.fields[fieldName].onValidate || this.props.onValidate || this.onValidate | ||
@@ -180,3 +178,3 @@ if (this.validateField(fieldName, fieldValue)) { | ||
validateFormAndUpdateState = () => { | ||
const fieldNames = Object.values(this.state.fields).map(field => field.name) | ||
const fieldNames = Object.values(this.props.fields).map(field => field.name) | ||
@@ -188,3 +186,2 @@ fieldNames.filter(field => field).forEach(fieldName => { | ||
: '' | ||
console.log('validating', fieldName, fieldValue, this.state.fields[fieldName]) | ||
this.validateFieldAndUpdateState(fieldName, fieldValue) | ||
@@ -195,4 +192,2 @@ }) | ||
onChange = (e, d) => { | ||
console.log('e: ', e) | ||
console.log('d: ', d) | ||
const changeEvent = d ? d : e.target | ||
@@ -203,3 +198,3 @@ this.validateFieldAndUpdateState(changeEvent.name, changeEvent.value) | ||
validateFieldsInput = () => { | ||
Object.values(this.state.fields).forEach(field => { | ||
Object.values(this.props.fields).forEach(field => { | ||
if (!field.name) throw new Error('Please provide a name value for all of your fields') | ||
@@ -214,13 +209,11 @@ if (!field.rules) | ||
// Add isRequired rule is field is required and not in a group | ||
Object.values(this.state.fields).forEach(field => { | ||
console.log('checking required for ', field.name) | ||
Object.values(this.props.fields).forEach(field => { | ||
if (field.required === true) { | ||
const newFields = this.state.fields | ||
const newFields = this.props.fields | ||
newFields[field.name].rules.push('isRequired') | ||
this.setState({ fields: newFields }) | ||
} | ||
console.log(field.required === true) | ||
}) | ||
this.validateFormAndUpdateState() | ||
if (this.props.validateOnLoad) Object.values(this.state.fields).map(field => this.removeAllErrors(field.name)) | ||
if (this.props.validateOnLoad) Object.values(this.props.fields).map(field => this.removeAllErrors(field.name)) | ||
} | ||
@@ -227,0 +220,0 @@ |
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
330430
655