react-form-validator-component
Advanced tools
Comparing version 1.7.1 to 1.7.2
{ | ||
"name": "react-form-validator-component", | ||
"version": "1.7.1", | ||
"version": "1.7.2", | ||
"main": "build/lib/index.js", | ||
@@ -5,0 +5,0 @@ "repository": "git@github.com:JDLT-Ltd/react-form-validator-component.git", |
@@ -35,4 +35,5 @@ import React from 'react' | ||
name: 'emailAddresses', | ||
rules: ['isEmailArray'], | ||
rules: ['isEmail'], | ||
required: 'test', | ||
defaultValue: 'notanemail, testing array', | ||
label: 'Email addresses' | ||
@@ -88,7 +89,10 @@ }, | ||
<Form> | ||
<Form.Field> | ||
<label>Your Emails</label> | ||
<input name="emailAddresses" onChange={onChange} content="notAnEmail" /> | ||
{this.renderErrors(errors.emailAddresses)} | ||
</Form.Field> | ||
<Form.Field | ||
control={'input'} | ||
label="Your emails" | ||
onChange={onChange} | ||
defaultValue={'notanemail, testing array'} | ||
name="emailAddresses" | ||
/> | ||
{this.renderErrors(errors.emailAddresses)} | ||
<Button onClick={() => alert('sure is')} disabled={!isFieldValid.emailAddresses}> | ||
@@ -95,0 +99,0 @@ Thats an Email! |
@@ -118,3 +118,3 @@ import React from 'react' | ||
// check if any other member of the group is valid | ||
if ( | ||
const otherMemberValid = | ||
this.state.groupValidation[groupName] && | ||
@@ -124,3 +124,4 @@ Object.entries(this.state.groupValidation[groupName]) | ||
.some(member => member.includes(true)) | ||
) { | ||
// if another member is valid and this field is empty, all is well | ||
if (otherMemberValid) { | ||
const fieldRules = this.props.fields[fieldName].rules | ||
@@ -131,10 +132,26 @@ const isFieldValid = this.validateRules(fieldName, fieldValue, fieldRules) | ||
newGroupValidation[groupName] = Object.assign({}, this.state.groupValidation[groupName], { | ||
[fieldName]: isFieldValid | ||
}) | ||
return this.setState({ | ||
groupValidation: newGroupValidation | ||
}) | ||
newGroupValidation[groupName] = !fieldValue | ||
? Object.assign({}, this.state.groupValidation[groupName], { | ||
[fieldName]: isFieldValid, | ||
invalidValuePresent: false | ||
}) | ||
: Object.assign({}, this.state.groupValidation[groupName], { | ||
[fieldName]: isFieldValid, | ||
invalidValuePresent: true | ||
}) | ||
return this.setState( | ||
{ | ||
groupValidation: newGroupValidation | ||
}, | ||
() => | ||
this.setState({ | ||
validation: Object.assign(this.state.validation, { | ||
[groupName]: | ||
Object.values(this.state.groupValidation[groupName]).some(member => member === true) && | ||
!this.state.groupValidation[groupName].invalidValuePresent | ||
}) | ||
}) | ||
) | ||
} | ||
// check if this field is valid | ||
// if no other member is valid, or this field has a value, check if this field is valid | ||
const fieldRules = this.props.fields[fieldName].rules | ||
@@ -154,3 +171,5 @@ const isFieldValid = this.validateRules(fieldName, fieldValue, fieldRules) | ||
validation: Object.assign(this.state.validation, { | ||
[groupName]: Object.values(this.state.groupValidation[groupName]).some(member => member === true) | ||
[groupName]: | ||
Object.values(this.state.groupValidation[groupName]).some(member => member === true) && | ||
!this.state.groupValidation[groupName].invalidValuePresent | ||
}) | ||
@@ -192,2 +211,3 @@ }) | ||
} else { | ||
if (this.state.validation[fieldName] === null) return null | ||
onValidate(fieldName, null) | ||
@@ -233,6 +253,6 @@ } | ||
} | ||
// Add isRequired rule if field is required and not in a group | ||
// Add isRequired rule if field is required or in a group | ||
addRequiredRuleToFields() { | ||
Object.values(this.props.fields).forEach(field => { | ||
if (field.required === true) { | ||
if (field.required === true || typeof field.required === 'string') { | ||
const newFields = this.props.fields | ||
@@ -239,0 +259,0 @@ newFields[field.name].rules.push('isRequired') |
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
317126
765