Search results

Mask Support in ASP.NET Core DatePicker control

18 Oct 2021 / 2 minutes to read

DatePicker has enableMask property that provides the option to enable the built-in date masking support.

tagHelper
Copied to clipboard
<ejs-datepicker id="datepicker" enableMask="true"></ejs-datepicker>

The mask pattern is defined based on the provided date format to the component. If the format is not specified, the mask pattern is formed based on the default format of the current culture.

Keys Actions
Up / Down arrows To increment and decrement the selected portion of the date.
Left / Right arrows and Tab To navigate the selection from one portion to next portion

The following example demonstrates default and custom format of DatePicker component with mask.

tagHelper
date-format.cs
Copied to clipboard
<div class="control-section">
        <div class="control_wrapper">
            <div class="pane">
                <div class="tabs-wrap">
                    <div class="wrap">
                        // Specifies the masked DatePicker without format property.
                        <ejs-datepicker id="datepicker" enableMask="true"></ejs-datepicker>
                    </div>
                </div>
                <div class="tabs-wrap">
                    <div class="wrap">
                       // Specifies the masked DatePicker with format property.
                       <ejs-datepicker id="format" enableMask="true" format="M/d/yyyy"></ejs-datepicker>
                    </div>
                </div>
            </div>
        </div>
    </div>
Copied to clipboard
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 Sample()
        {
            return View();
        }
    }
}

Configure Mask Placeholder

You can change mask placeholder value through property maskPlaceholder. By default , it takes the full name of date and time co-ordinates such as day, month, year, hour etc.

While changing to a culture other than English, ensure that locale text for the concerned culture is loaded through load method of L10n class for mask placeholder values like below.

Copied to clipboard
//load the locale object to set the localized mask placeholder value
L10n.load({
'de': {
    'datepicker': { day: 'Tag' , month: 'Monat', year: 'Jahr' }
}
});

The following example demonstrates default and customized mask placeholder value.

tagHelper
mask-placeholder.cs
Copied to clipboard
@{
    var maskPlaceholderValue = new Syncfusion.EJ2.Calendars.DatePickerMaskPlaceholder { Day = "d", Month = "M", Year = "y" };
}
<div class="control-section">
        <div class="control_wrapper">
            <div class="pane">
                <div class="tabs-wrap">
                    <div class="wrap">
                        // Specifies the masked DatePicker without mask placeholder.
                        <ejs-datepicker id="datepicker" enableMask="true"></ejs-datepicker>
                    </div>
                </div>
                <div class="tabs-wrap">
                    <div class="wrap">
                       // Specifies the masked DatePicker with mask placeholder.
                       <ejs-datepicker id="format" enableMask="true" maskPlaceholder = "@maskPlaceholderValue" ></ejs-datepicker>
                    </div>
                </div>
            </div>
        </div>
    </div>
Copied to clipboard
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 Sample()
        {
            return View();
        }
    }
}