I try to do a function that determine if a state is empty what i do so far is
const { startDate, endDate ,classname} = this.state;
if(!startDate || !endDate || !selectedRoom || !selectedTrainer || !classname){
if(!classname){
this.setState({classnamevalid : 'errorBorder_Invalid'});
} else {
this.setState({classnamevalid : ''});
}
if(!startDate){
this.setState({startDatevalid : 'errorBorder_Invalid'});
}else{
this.setState({startDatevalid : ''});
}
if(!endDate){
this.setState({endDatevalid : 'errorBorder_Invalid'});
} else {
this.setState({endDatevalid : ''});
}
} else {
console.log(proceed)
}
what i did so far is , and as i thought it wont work. "i know its stupid "
if(!startDate || !endDate || !selectedRoom || !selectedTrainer || !classname){
const validation = ["startDate", "endDate" ,"classname"];
var i;
for (i = 0; i < validation.length; i++) {
if(!this.state.validation[i]){
this.setState({validation[i] : 'errorBorder_Invalid'});
} else {
this.setState({validation[i] : ''});
}
}
} else {
console.log(proceed)
}