I have dozen of input components. When some of them don't pass validation it gets coresponding propperty "invalidInputName = true" and class "hasError".
When user start typing in those input again, i need to remove "hasError" by changing "invalidInputName" to false. I want to write function clearValidation() witch will be accepting name of parameter and change it to false.
class ExchangeForm extends React.Component {
constructor(props) {
super(props);
this.state = {
paymentAmountValidation: false,
invalidAccountNum: false,
invalidPhone: false,
invalidCheck: false
}
}
// this function toogles input to normal state.
// I want to pass the name of property which i want to reset
// For example: clearValidation('invalidPhone') must work as
// this.setState({ ...this.state, invalidPhone: false }).
// But best i've done was { property: propery:false } :(
// I have to change this.state only with setState()
clearValidation(property){
this.setState({ ...this.state, property })
}
validation(){
//it toogles state properties to true if found any error
}
}
Is it possible?