DatePicker default value on open

1 Answer 656 Views
Date/Time Pickers
FIMS Computing Services FIMS - UWO
Top achievements
Rank 1
Iron
FIMS Computing Services FIMS - UWO asked on 09 May 2022, 07:19 PM

I have a dialog box that includes a date picker for an expiry date field that is null be default.

If I select an expiry date say a year into the future, close the dialog box and reopen it, the calendar in the datepicker opens to my last selected date instead of today's date.

Is there anyway to force the calendar to always open to today if a date is not set in the datepicker instead of remembering its last position.

It seems to me, I should be able to get the calendar component in the open event  of the datepicker and then set the initial date. Is that possible?

 

Thanks,

Charlotte

1 Answer, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 12 May 2022, 01:51 PM

Hi,

Thank you for the provided information.

Indeed, you are on the right track, you can set a default value within the Open event of the DatePicker, and based on a null evaluation, set a default value through the value() method. For example:

.Events(e=>e.Open("onOpen"))

<script>
      function onOpen(e){
            if(e.sender.value() == null){
                e.sender.value(new Date());
            }
      }
</script>    

Here is a Telerik REPL that illustrates this approach.

If this does not help, please consider sharing additional information regarding the scenario you currently are implementing. For example, a code snippet showing both the Dialog and DatePicker configuration would be beneficial for the case, as it will give me a better understanding of the desired outcome and based on it, provide further guidance in order to achieve the desired result.

Best Regards,
Alexander
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

FIMS Computing Services FIMS - UWO
Top achievements
Rank 1
Iron
commented on 12 May 2022, 03:00 PM

That worked perfectly!

Thanks,

Charlotte

Tags
Date/Time Pickers
Asked by
FIMS Computing Services FIMS - UWO
Top achievements
Rank 1
Iron
Answers by
Alexander
Telerik team
Share this question
or