daterangepicker - shows previous selected ranges as well #2287
-
I am using daterangepicker plugin to get the date ranges. After clicking apply button multiple times, it gives all the previous date ranges which were selected rather than giving the current selected date range. I just need the current selected range instead of all previous ranges. Can someone suggest a fix. Stackoverflow link: https://stackoverflow.com/questions/73877693/daterangepicker-shows-previous-selected-ranges-as-well HTML: Javascript:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You're creating a form submit handler inside the callback function for the date range changing, so every time a new date range is selected, you attach another form submit handler to the form. If someone selects 3 date ranges, you now have 3 functions that will run when the form gets submitted, not one. Instead of doing that, update some global start_date/end_date variables that exist outside of the callback function and move your form submit handler outside that function too. Or, have the callback function populate some hidden inputs in your form, and then just treat them as any other input in your code to handle the form, which doesn't need to be inside the daterangepicker callback. |
Beta Was this translation helpful? Give feedback.
You're creating a form submit handler inside the callback function for the date range changing, so every time a new date range is selected, you attach another form submit handler to the form. If someone selects 3 date ranges, you now have 3 functions that will run when the form gets submitted, not one.
Instead of doing that, update some global start_date/end_date variables that exist outside of the callback function and move your form submit handler outside that function too.
Or, have the callback function populate some hidden inputs in your form, and then just treat them as any other input in your code to handle the form, which doesn't need to be inside the daterangepicker callback.