I want create the textfields based on the count entered by the user. I have gone through many related questions, I cannot find the result as I want.
For Example: If the user enter 5 as input.. I want to create 5 text boxes for entering 5 people Name and Mobile.
How can I achieve this?
TextField to get count
<GridItem xs={12} sm={12} md={12}>
<TextField
id="sp_Inhouse"
label="Number of Pilots Available "
type="number"
fullWidth
className={classes.textField}
value={this.state.sp_Inhousecount}
error={!!this.state.sp_InhouseError}
helperText={this.state.sp_InhouseError}
onChange={this.handleChangeInhouse}
margin="normal"
required
/>
</GridItem>
Tried adding the textboxes based on button click. It works fine. but I want the result as explained.
<GridItem xs={12} sm={12} md={12}>
<Button color="primary" onClick={this.handleCreatePilots}>
<AddIcon /> Add Pilots
</Button>
{this.state.inhouse.map((index) => {
return (
<div key={index}>
<TextField
id="sp_Name"
label="Name "
type="number"
fullWidth
/>
<TextField
id="sp_Mobile"
label="Name "
type="number"
fullWidth
/>
</div>
)
})
}
</GridItem>
handleCreatePilots=()=>{
this.setState({
inhouse:[...this.state.inhouse,'']
})
}
inhouseis a different value or are you saving the total number in that state variable?