
Security News
Django Joins curl in Pushing Back on AI Slop Security Reports
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
react-nested-validation
Advanced tools
A toolkit for performing nested validation of React forms.
There is a diverse array of React packages designed to help render and validate forms. However there was no obvious choice that provided the following features:
Ability to deeply nest forms and collate errors at the top level.
Allow for complex validation rules.
Unopinionated about how to render presentational components.
We found a need for a light weight validation toolkit that could be
used with a variety of presentational frameworks, and so we made
react-nested-validation
.
There are three main components:
Forms.
Validator functions.
React component wrappers.
Forms are the main interface for designing both the validation, and the nested structure of your validation. Forms are ES6 classes that contain links to subforms, and allow for methods to be overidden in order to validate both fields and general form errors.
Validator functions are conveniences for performing common validation operations, e.g. required fields.
The React component wrappers are two higher-order components to help
apply Form
s to your presentational React comonents.
import Form, {required} from 'react-nested-validation'
class MovieForm extends Form {
fieldValidators = {
title: required()
}
}
import React from 'react'
import {asForm} from 'react-nested-validation'
@asForm({form: BasicForm})
class Movie extends React.Component {
render() {
const {form} = this.props
const {values, errors, touched} = form
return (
<div>
<input
name="title"
value={values.title}
/>
<input
name="year"
value={values.year}
/>
</div>
)
}
}
import Form, {required} from 'react-nested-validation'
class DirectorForm extends Form {
fieldValidators = {
name: required()
}
}
class MovieForm extends Form {
fieldValidators = {
title: required()
}
nested = {
director: DirectorForm
}
}
import React from 'react'
import {asForm} from 'react-nested-validation'
@asForm({form: SubForm})
class Sub extends React.Component {
render() {
const {form} = this.props
const {values, errors, touched} = form
// Render your form here.
}
}
@asForm({form: SuperForm})
class Super extends React.Component {
render() {
const {form} = this.props
const {values, errors, touched} = form
return (
<div>
<Sub
form={values.sub}
prefix="sub"
/>
</div>
)
}
}
import Form, {required} from 'react-nested-validation'
class MovieForm extends Form {
fieldValidators = {
title: required()
}
}
class MovieListForm extends Form {
nested = [
MovieForm
]
}
import React from 'react'
import {asForm} from 'react-nested-validation'
@asForm({form: SubForm})
class Sub extends React.Component {
render() {
const {form} = this.props
const {values, errors, touched} = form
// Render your form here.
}
}
@asForm({form: SuperForm})
class Super extends React.Component {
render() {
const {form} = this.props
const {values, errors, touched} = form
return (
<div>
{
values.map((sub, ii) => (
<Sub
form={sub}
prefix={ii}
/>
))
}
</div>
)
}
}
FAQs
A toolkit for performing nested validation of React forms.
We found that react-nested-validation demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.