We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to set the [default date] before user has selected a value

Thread ID:

Created:

Updated:

Platform:

Replies:

145997 Jul 17,2019 02:40 AM UTC Jul 17,2019 01:03 PM UTC ASP.NET Core - EJ 2 1
loading
Tags: DatePicker
Wayne
Asked On July 17, 2019 02:41 AM UTC

I have a registration form where a user has to select a date.

1) I do not want a date entered into the field initially (Visually) when the form is loaded.
2) When the user clicks the Calendar, I want to display todays date as the initial value, the starting point for navigation purposes.


If I bind the "value" to todays date, then the field displays this date when the form is initially loaded, implicitly filling in the date.
I want the user to select a date explicitly and not to provide a "default" selected date.

This means I require the control to have an initial date.

Here is my code which does not achieve what I want:

@{
int year = DateTime.Now.Year;
DateTime firstDay = new DateTime(year-1 , 1, 1);
DateTime lastDay = new DateTime(year+1 , 12, 31);
Model.RegistrationDate = DateTime.Now;
}
<div id="datepicker-control">
<ejs-datepicker id="datepicker" min=@firstDay max=@lastDay value=@Model.RegistrationDate placeholder="Registration Date">ejs-datepicker>
div>

Christopher Issac Sunder K [Syncfusion]
Replied On July 17, 2019 01:03 PM UTC

Hello Wayne, 

Greetings from Syncfusion support.  

We have checked with the provided code snippet and you have set a date value to the value property of DatePicker component. If we set any value, the datePicker will take that as initial value and that value will be displayed on load. By default, our DatePicker component will take the Today’s date as default date. So, we suggest you not to set the value property on initial rendering. 

Please see our online sample for DatePicker which shows nothing in the field and today’s date is set as default in the dropdown calendar, 

Please get back to us if we misunderstood your query.  

Thanks,
Christo 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon