0

I have a DatePicker that has todayButton = Vandaag shown in the code and image below. I wanted to see if I can activate the todayButton by clicking on any of my select option instead of clicking Vandaag. I need some idea where to start. I appreciate any insight on this.

```<div className="status">
<select name="status" id="status">
<option selected>1</option>
<option>2</option>
</select></div>```


```DatePicker
  todayButton="Vandaag"
  selected={startDate}
  onChange={(date) => setStartDate(date)}
/>```
    
        
        

enter image description here

1 Answers1

1

I am not 100% sure but from what i understand you want to change the date to today's date from the select. Instead of going in a round about manner of selecting today button you can update startDate using setStartTime when you select corresponding option in select.

const onSelectChange = (e) => {
 if (e.target.value === "Today") {
    setStartDate(new Date())
 }
}
  • Its not working, it doesn't change the date in the datepicker to today. I don't know what I'm missing I tried different approach similar to that one but It never taken effect to the date picker date. – Jan Dohinog Jun 05 '21 at 08:02
  • Did you check if the state is update properly. Console log startDate and see if the update is happening due to the select option change – Mathew Joseph Jun 05 '21 at 08:06
  • setStartDate(date)} /> – Jan Dohinog Jun 05 '21 at 08:21
  • – Jan Dohinog Jun 05 '21 at 08:21
  • I am trying to see I I can apply this one instead: https://stackoverflow.com/questions/21662734/click-on-an-element-triggers-the-click-on-another-element-jquery – Jan Dohinog Jun 05 '21 at 08:30