I want to add required attribute in MUI TextField based on a condition

272 views Asked by At

I want to add required attribute in MUI TextField based on a condition.


Var flag = false
If (investment>50000 && investment<5000){
flag = true
}

<TextField 
required = {flag}
id="shop-name" 
label="Shop Name" 
variant="outlined" />

This doesn't seems to work

1

There are 1 answers

0
Akis On

Seems you have your if statement in the wrong way and you wanted the investment number to be between 50000 and 5000. So change it to

if (investment > 5000 && investment < 50000) {
  flag = true;
}