jdtcn / BlazorDateRangePicker

A Blazor component for choosing date ranges and dates
MIT License
182 stars 35 forks source link

How to clean the datepicker value #11

Closed DavidArtifacts closed 4 years ago

DavidArtifacts commented 4 years ago

Hi, is there a way for cleaning the datepicker? I tried using the OnClose event but is called also when the Apply button is clicked, so I can't find a correct way to clean or restart the value 😞.

I think it's missing the OnCancel event, in the original doc they used it to perform clean:

$('#daterange').on('cancel.daterangepicker', function(ev, picker) { //do something, like clearing an input $('#daterange').val(''); });

Hope there is someone that can helps me.

Btw nice port! 👍

jdtcn commented 4 years ago

Hi!

Have you tried to use @bind-StartDate="StartDate" @bind-EndDate="EndDate" binding and then set StartDate = EndDate = null when you need to?

Also when the cancel button is clicked the picker will restore previously selected values.

OnCancel event is indeed missing, so I've added it in 2.1.0 version. It returns true if selection is cancelled by button, and false if by backdrop click.

DavidArtifacts commented 4 years ago

In my case, I can't bind start and end dates, because the datepickers are generated by a forloop... or maybe I could use an array to assing the values, it's going to be kinda messy but should work.

Hope the version 2.1.0 is ready soon 😄 .

Feel free to close issue if there is not another recomendation.

Thank you!.

jdtcn commented 4 years ago

You're welcome. Version 2.1.0 already on nuget.