react-form-validator-component
Advanced tools
Comparing version 1.5.1 to 1.5.2
@@ -0,0 +0,0 @@ module.exports = { |
{ | ||
"name": "react-form-validator-component", | ||
"version": "1.5.1", | ||
"version": "1.5.2", | ||
"main": "build/lib/index.js", | ||
@@ -5,0 +5,0 @@ "repository": "git@github.com:JDLT-Ltd/react-form-validator-component.git", |
@@ -26,23 +26,5 @@ import React from 'react' | ||
name: 'emailAddresses', | ||
rules: ['isEmailArray'], | ||
required: 'test', | ||
rules: ['isEmailArray', 'isRequired'], | ||
required: true, | ||
label: 'Email addresses' | ||
}, | ||
something: { | ||
name: 'something', | ||
rules: ['isPhoneNumber'], | ||
required: 'test', | ||
label: 'Something' | ||
}, | ||
number: { | ||
name: 'number', | ||
rules: ['isNumeric'], | ||
required: 'group2', | ||
label: 'number' | ||
}, | ||
name: { | ||
name: 'name', | ||
rules: ['isFullName'], | ||
required: 'group2', | ||
label: 'name' | ||
} | ||
@@ -75,17 +57,2 @@ } | ||
</Form.Field> | ||
<Form.Field> | ||
<label>Something</label> | ||
<Input name="something" onChange={onChange} /> | ||
{this.renderErrors(errors.something)} | ||
</Form.Field> | ||
<Form.Field> | ||
<label>Group 2 Number</label> | ||
<Input name="number" onChange={onChange} /> | ||
{this.renderErrors(errors.number)} | ||
</Form.Field> | ||
<Form.Field> | ||
<label>Group 2 Name</label> | ||
<Input name="name" onChange={onChange} /> | ||
{this.renderErrors(errors.name)} | ||
</Form.Field> | ||
{<span>Form is {isFormValid ? 'valid' : 'not valid'}</span>} | ||
@@ -92,0 +59,0 @@ <hr /> |
@@ -95,2 +95,3 @@ import React from 'react' | ||
if ( | ||
this.state.groupValidation[groupName] && | ||
Object.entries(this.state.groupValidation[groupName]) | ||
@@ -133,7 +134,7 @@ .filter(field => !field.includes(fieldName)) | ||
const groupName = | ||
this.props.fields[fieldName].required && typeof this.props.fields[fieldName].required | ||
? this.props.fields[fieldName].required | ||
this.state.fields[fieldName].required && typeof this.state.fields[fieldName].required === 'string' | ||
? this.state.fields[fieldName].required | ||
: undefined | ||
// ensure that empty non-required fields pass validation and don't throw errors | ||
if (!groupName && fieldValue.length === 0) { | ||
if (!groupName && !this.state.fields[fieldName].required && fieldValue.length === 0) { | ||
this.setState( | ||
@@ -147,7 +148,5 @@ { | ||
} | ||
if (groupName) { | ||
return this.validateGroup(fieldName, fieldValue, groupName) | ||
} | ||
// standard validation | ||
@@ -163,3 +162,3 @@ const fieldRules = this.state.fields[fieldName].rules | ||
validateFieldAndUpdateState(fieldName, fieldValue) { | ||
const onValidate = this.props.fields[fieldName].onValidate || this.props.onValidate || this.onValidate | ||
const onValidate = this.state.fields[fieldName].onValidate || this.props.onValidate || this.onValidate | ||
@@ -178,4 +177,3 @@ if (this.validateField(fieldName, fieldValue)) { | ||
validateFormAndUpdateState = () => { | ||
const fieldNames = Object.values(this.props.fields).map(field => field.name) | ||
console.log('fieldNames are', fieldNames) | ||
const fieldNames = Object.values(this.state.fields).map(field => field.name) | ||
@@ -187,3 +185,3 @@ fieldNames.filter(field => field).forEach(fieldName => { | ||
: '' | ||
console.log('validating', fieldName) | ||
console.log('validating', fieldName, fieldValue, this.state.fields[fieldName]) | ||
this.validateFieldAndUpdateState(fieldName, fieldValue) | ||
@@ -198,3 +196,3 @@ }) | ||
validateFieldsInput = () => { | ||
this.props.fields.forEach(field => { | ||
Object.values(this.state.fields).forEach(field => { | ||
if (!field.name) throw new Error('Please provide a name value for all of your fields') | ||
@@ -209,3 +207,3 @@ if (!field.rules) | ||
this.validateFormAndUpdateState() | ||
if (this.props.validateOnLoad) Object.values(this.props.fields).map(field => this.removeAllErrors(field.name)) | ||
if (this.props.validateOnLoad) Object.values(this.state.fields).map(field => this.removeAllErrors(field.name)) | ||
} | ||
@@ -212,0 +210,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
328960
630