Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closing modal to reset date selection #262

Open
db-qc opened this issue Sep 5, 2022 · 2 comments
Open

Closing modal to reset date selection #262

db-qc opened this issue Sep 5, 2022 · 2 comments

Comments

@db-qc
Copy link

db-qc commented Sep 5, 2022

Hi!

So I had something I thought would be quite simple to achieve. Currently, when the modal is closed, the date selection currently selected is set. What I wanted to do was when the modal is closed (i.e. without hitting 'apply'), I wanted to cancel the current selection.

I have tried resetting the picker.element.val using picker.oldStartDate and picker.oldEndDate when onHide was called, which kind of works but this causes a problem when I try and use onApply as onHide called before on apply.

I tried using onEvent but that's fired twice, so even if I'm listening to a certain event it fires twice.

What I'd really like to achieve is replicating exactly what the 'Cancel' button does - which I thought would be simple :D

Does anyone have an idea on how to do this?

@skratchdot
Copy link
Owner

view the story details for "change initialSettings (range data)":
https://projects.skratchdot.com/react-bootstrap-daterangepicker/?path=/story/daterangepicker--change-initialsettings-range-data

you probably need to make use of a ref.

const keyRef = useRef(Date.now());

and make sure you put that in your picker

return <DateRangePicker key={keyRef.current} />

anytime you want to render the picker with 'fresh initialSettings', just update the ref. it's a hacky workaround due to this not being a typical controlled react component.

@emanuallan
Copy link

emanuallan commented Nov 14, 2022

Here's what worked for me in the onHide prop

(pickerRef as any).current.$picker
        ?.data('daterangepicker')
        ?.setStartDate(date);
      (pickerRef as any).current.$picker
        ?.data('daterangepicker')
        ?.setEndDate(date);

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants