This is a migrated thread and some comments may be shown as answers.

Set a default date on OPEN but don't display it

1 Answer 137 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
Janice
Top achievements
Rank 1
Janice asked on 16 Feb 2021, 01:02 PM

For our date fields when no date has yet been selected, on opening the calendar control, we want the start date to be set to a specific date. Is this possible?  Not today's date but a date in the past. 

I can set a default date but then on reaching that page the default date is showing in the input  - we don't want that.  On reaching the page , the date must show as blank and only on opening of the calendar, the date should be defaulting to our specified date. Then once a date is selected it can be shown in the input. 

1 Answer, 1 is accepted

Sort by
0
Anton Mironov
Telerik team
answered on 18 Feb 2021, 09:06 AM

Hi Janice,

Thank you for the details provided.

In order to achieve the desired behavior, I would recommend using a CSS styling. Create your Kendo UI DatePicker as an input with a custom class. Let the styling of this class is "color: transparent;" (the value of the input will be invisible). Use the initialization scope of the DatePicker to handle its "open" Event. In the Event handler remove the class from the input and the value will be visible. Here is an example:

// HTML
 <input id="datepicker" value="10/10/2011" title="datepicker" style="width: 100%" class="hideValue"/>
//JavaScript
        $(document).ready(function() {
          $("#datepicker").kendoDatePicker({
            open: function(e) {
              $("#datepicker").removeClass("hideValue"); 
            }
          });
        });
// CSS
  .hideValue{
    color: transparent;
  }

The complete implementation and behavior could be found in the following dojo example:

Give the approach above a try and let me know if further assistance is needed.


Kind Regards,
Anton Mironov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Date/Time Pickers
Asked by
Janice
Top achievements
Rank 1
Answers by
Anton Mironov
Telerik team
Share this question
or