Available in the OSS Version

Editors - Date Picker

This sample demonstrates the igDatePicker control.

Book your flight

This sample is designed for a larger screen size.

On mobile, try rotating your screen, view full size, or email to another device.

The igDatePicker allows you to have an input field with a drop-down calendar and a specified date format display. The control supports localization by recognizing different regional options exposed from the browser, and also supports validation.

Code View

Copy to Clipboard
<!DOCTYPE html>
<html>
<head>
    <!-- Ignite UI for jQuery Required Combined CSS Files -->
    <link href="http://cdn-na.infragistics.com/igniteui/2024.2/latest/css/themes/infragistics/infragistics.theme.css" rel="stylesheet" />
    <link href="http://cdn-na.infragistics.com/igniteui/2024.2/latest/css/structure/infragistics.css" rel="stylesheet" />
    <style>
        h3 {
            font-size: 20px;
            margin-bottom: 20px;
        }

        .group-fields {
            margin-bottom: 10px;
        }

        .group-fields label {
            display: block;
            line-height: 18px;
        }

        .group-fields .inline {
            display: inline;
        }

        .group-fields .ui-igcheckbox-normal {
            margin-right: 5px;
            float: left;
        }

        .group-fields .ui-igedit-container {
            width: 230px;
        }

        .clearfix:after {
            content: "";
            display: table;
            clear: both;
        }

        .group-fields.clearfix > div {
            float: left;
            margin-right: 10px;
        }
    </style>

    <script src="http://ajax.aspnetcdn.com/ajax/modernizr/modernizr-2.8.3.js"></script>
    <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
    <script src="http://code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script>

    <!-- Ignite UI for jQuery Required Combined JavaScript Files -->
    <script src="http://cdn-na.infragistics.com/igniteui/2024.2/latest/js/infragistics.core.js"></script>
    <script src="http://cdn-na.infragistics.com/igniteui/2024.2/latest/js/infragistics.lob.js"></script>
</head>
<body>
    <h3>Book your flight</h3>
    <div class="group-fields">
        <label for="currentTime">Right now it is</label>
        <input id="currentTime" />
    </div>
    <div class="group-fields clearfix">
        <div>
            <label for="departure">Departure</label>
            <input id="departure" />
        </div>
        <div>
            <label for="departureTime">Around</label>
            <input id="departureTime" />
        </div>
    </div>
    <div class="group-fields clearfix">
        <div>
            <label for="return">Return</label>
            <input id="return" />
        </div>
        <div>
            <label for="returnTime">Around</label>
            <input id="returnTime" />
        </div>
    </div>
    <div class="group-fields">
        <input id="oneWayTicket" />
        <label for="oneWayTicket">One way ticket</label>
    </div>

    <script type="text/javascript">
        $(function () {
            var today = new Date(),
            tomorrow = new Date(new Date().getTime() + 24 * 60 * 60 * 1000);

            $("#currentTime").igDateEditor({
                dateInputFormat: "dateTime",
                value: new Date(),
                dataMode: "date",
                readOnly: true
            });

            $("#departure").igDatePicker({
                dateInputFormat: "ddd, MMM d, yyyy",
                value: today,
                regional: "en-US",
                dataMode: "date",
                datepickerOptions: {
                    minDate: today
                        },
                valueChanged: function (evt, ui) {
                    if (ui.newValue instanceof Date) {
                        var nextDay = new Date(ui.newValue.getTime() + 24 * 60 * 60 * 1000);
                        // V.S. April 3rd 2019, Set the min date for return to be at least 1 day after departure
                        var currentValue = $("#return").igDatePicker("option", "value");
                        // Depending on the current value, first set minDate OR first set value in order to avoid notifier showing up
                        if (currentValue.getTime() > nextDay.getTime()) {
                            $("#return").igDatePicker("option", "datepickerOptions", {
                                minDate: nextDay
                            }).igDatePicker("option", "value", nextDay)
                        } else {
                            $("#return").igDatePicker("option", "value", nextDay).igDatePicker("option", "datepickerOptions", {
                                minDate: nextDay
                            })
                        }
                    }
                 }
            });

            $("#departureTime").igDateEditor({
                dateInputFormat: "hh:mm",
                value: new Date(),
                dataMode: "date",
                buttonType: "spin",
                width: 100
            });
            $("#return").igDatePicker({
                value: tomorrow,
                dateInputFormat: "ddd, MMM d, yyyy",
                regional: "en-US",
                dataMode: "date",
                    datepickerOptions: {
                        minDate: tomorrow,
                        numberOfMonths: [1, 2]
                    }
            });

            $("#returnTime").igDateEditor({
                dateInputFormat: "hh:mm",
                value: new Date(),
                dataMode: "date",
                buttonType: "spin",
                width: 100
            });

            $("#oneWayTicket").igCheckboxEditor({
                checked: false,
                valueChanged: function (evt, ui) {
                    if (ui.newState == true) {
                        $("#return").igDatePicker("option", "disabled", true);
                        $("#returnTime").igDateEditor("option", "disabled", true);

                    }
                    else {
                        $("#return").igDatePicker("option", "disabled", false);
                        $("#returnTime").igDateEditor("option", "disabled", false);

                    }
                }
            });

        });

    </script>
</body>
</html>