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.1 to 1.5.2

0

.eslintrc.js

@@ -0,0 +0,0 @@ module.exports = {

2

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

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