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.7.1 to 1.7.2

2

package.json
{
"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')

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