Contact Support
Strict Mode
19 Dec 20223 minutes to read
The strictMode is an act, that allows the user to enter only the valid date within the specified min/max
range in textbox. If the date is invalid, then the component will stay with the previous value. Else, if the date is out of range, then the component will set the date to the min/max date.
The following example demonstrates the DatePicker in strictMode
with min/max range of 5th to 25th in a month of May. Here, it allows to enter only the valid date within the specified range. If you are trying to enter the out-of-range value as like 28th of May, then the value will set the max date of 25th May, since the value 28th is greater than max value of 25th. Or else if you are trying to enter the invalid date, then the value will stay with the previous value.
<ejs-datepicker id="datepicker" strictmode=true format="dd/MM/yyyy" placeholder="Enter date" value="ViewBag.value" min="ViewBag.minDate" max="ViewBag.maxDate"></ejs-datepicker>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace EJ2CoreSampleBrowser.Controllers
{
public class HomeController: Controller
{
public ActionResult DefaultFunctionalities()
{
ViewBag.value = new DateTime(2018, 5, 28);
ViewBag.minDate= new DateTime(2018, 5, 5);
ViewBag.maxDate = new DateTime(2018, 5, 25);
return View();
}
}
}
By default, the DatePicker act in strictMode false
state allows to enter the invalid or out-of-range date in textbox.
If the date is out-of-range or invalid, then the model value will be set to out of range
date value or null
respectively with highlighted error
class to indicate the date is out of range or invalid.
The following example demonstrates the strictMode
as false
. Here, it allows to enter the valid or invalid value in textbox. If you are entering out-of-range or invalid date value, then the model value will be set to out of range
date value or null
respectively with highlighted error
class to indicate the date is out of range or invalid.
<ejs-datepicker id="datepicker" format="dd/MM/yyyy" placeholder="Enter date" value="ViewBag.value" min="ViewBag.minDate" max="ViewBag.maxDate"></ejs-datepicker>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace EJ2CoreSampleBrowser.Controllers
{
public class HomeController: Controller
{
public IActionResult DefaultFunctionalities()
{
ViewBag.value = new DateTime(2018, 5, 28);
ViewBag.minDate= new DateTime(2018, 5, 5);
ViewBag.maxDate = new DateTime(2018, 5, 25);
return View();
}
}
}
NOTE
If the value of
min
ormax
properties changed through code behind, then you have to update thevalue
property to set within the range.