I am receiving a props data is look like
data: [
{
rowNumber: 1,
specification: null,
validationMessage: [
{
isExists: true,
errors: [
{
errorCode: "PredicateValidator",
errorMessage: "ERR: Length value is not in correct "
},
{
errorCode: "PredicateValidator",
errorMessage: "Height Unit is not in correct "
},
]
}
]
},
{
rowNumber: 2,
specification: null,
validationMessage: [
{
isExists: false,
errors: []
}
]
},
]
In my render I have a button and I am trying to disable/ enable that button based on my errorMessage. If my eoorMessage contains a word "ERR:" I will disable the button otherwise it will be enabled. Note: My errorMessage may be empty or may or may not have the word "Err:" word. If "ERR:" word exist any of my errorMessage I have to disable the button
I have tried this but it says x is not defined. How can I overcome this?
render() {
const hasError = this.props.data ? this.props.data.find((x) => x.validationMessage.erros.find(z => z.errorMessage.indexof("ERR:"))) : ''
return (
<div>
{(this.props.data) ?
<div>
(hasError) ?
<Button variant="contained" className={classes.button} onClick={this.handleSave}>Continue</Button>
:
<Button variant="contained" disabled={true} className={classes.button} onClick={this.handleSave}>Continue</Button>
<Button variant="contained" className={classes.button} onClick={this.handleCancle}> Cancel</Button>
</div>
: ''}
</div>
);