I'm stuck in my project. I need to show/hide two dropdown selections on toggle switch (on/off).
This is my sample code:
handleSwitch = (event, index) => {
// TODO if true then display the empty dropdown selectionss
console.log("event.target.checked", event.target.checked);
console.log("index", index);
this.setState({ toggleInputField: true });
}
{days.map((day, dayIndex) =>
<Container key={dayIndex}>
<Row>
<Col>
<Switch
nativeControlId='my-switch'
checked={regularHours && regularHours.periods && regularHours.periods[this.findArrayIndex(regularHours.periods, day.openDay, 'openDay')] ? true : false}
onChange={(e) => this.handleSwitch(e, dayIndex)} />
</Col>
<Col>
<select className="form-control m-b--15" value={day.openTime} name={'openTime' + dayIndex} onChange={(event) => this.handleAddTimes(event, day)}>
<option value="" key={0}>Select Time Open</option>
{
openingHours && openingHours.map((time, index) =>
<option value={time} key={index}>{time}</option>
)
}
</select>
</Col>
<Col>
<select className="form-control m-b--15" value={day.closeTime} name={'closeTime' + dayIndex} onChange={(event) => this.handleAddTimes(event, day)}>
<option value="" key={0}>Select Time Closed</option>
{
openingHours && openingHours.map((time, index) =>
<option value={time} key={index}>{time}</option>
)
}
</select>
</Col>
<Row>
</Container>)}
I just don't have an idea to keep track of the checked toggle switches and display accordingly the dropdown selections.
Any ideas? I would gladly appreciate any help. Thanks!