Handling multiple date-ranges in a single parent
See original GitHub issueI’m using react-dates in an advanced search component that incorporates multiple date-range fields.
I’m trying to figure out the best way to detect which of the date-range pickers is being changed and handle the event accordingly in the onFocusChange and onDateChange callbacks without writing a separate handler with superficial differences to target the appropriate attribute for each instance of the component.
Is there a way to access the event target within the defined callbacks?
I’m imagining something along the lines of:
onFocusChange(event, focusedInput){
var newState = object.assign({}, this.state);
newState[event.target.id].focusedInput = focusedInput;
this.setState(newState);
}
But maybe it would be a better approach to store another variable on the state which stores the focused date-range picker?
Any insight would be greatly appreciated!
Update: I’ve written a closure to return a case-specific handler for each field which is adequate to my use case, but I am still curious if it’s possible to access the source event.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:7
Top GitHub Comments
I am using multiple DateRangePicker that dynamically added in single page. There is another solution.
Hi @tyleralves , My solution was to write a closure that returns a function specific to the active react dates instance.
In my case there was one instance to set a range for when a record was created, and another range for the date the record was most recently modified: called ‘created’ and ‘changed’.
Here are my two handler functions for focus and date changes respectively:
and here’s how I used it in my component:
and then in the ReactDates instances:
Hope this is helpful in your case as well!