I have written a custom Input class component.
class Input extends React.Component {
validate = () => {
// validation logic
}
handleChange = () => {this.validate()}
render () {
return <input onChange={this.handleChange} name={this.props.name} type={this.props.type}/>
}
}
In a Form component I use it like this.
class Form extends React.Component {
handleSubmit () => {
// trigger Input validation here
}
render () {
return <form onSubmit={this.handleSubmit}>
<Input name="abc" type=""/>
<Input name="abc" type="password"/>
</form>
}
}
There can be more than 20 Input component nested in Form component. My question is how do I trigger validations of Input components from the Parent Form component when the form is submitted?. Since I have a lot of Input components I need to a way to call all the validation method of every Input instance.