0

I have a really annoying issue with JQuery UI Datepicker.

datpicker initialisation

<script>
    var dateToday = new Date();
    $(function () {
        $(".datepicker").datepicker(
            {
                minDate: dateToday,
                dateFormat: "dd/mm/yy",
                showOtherMonths: true,
                selectOtherMonths: true,
                showButtonPanel: true,
                changeMonth: true,
                changeYear: true,
                gotoCurrent: true
            });
    });
</script>

deadline field

<div class="form-group">
    <div class="col-xs-12">
        @Html.EditorFor(model => model.Deadline, new { htmlAttributes = new { @class = "form-control datepicker", placeholder = Html.DisplayNameFor(model => model.Deadline) } })
    </div>
</div>

It works fine in that I am unable to select days before today, and I can select future dates and for the most part it works normally.

However, if I select another date from this month, I get a validation error complaining the value must be a date.

How is this even possible, if I haven't specified minimum date requirements anywhere apart from minDate in the initialiser?

enter image description here

Bassie
  • 9,529
  • 8
  • 68
  • 159
  • 1
    Are you using unobtrusive client side validation (using `jquery.validate.js`) with `@Html.ValidationMessageFor()` in your view? –  Nov 24 '17 at 04:51
  • @StephenMuecke Yes I am – Bassie Nov 24 '17 at 04:52
  • 1
    By default, that plugin validates dates based on `MM/dd/yyyy` format, so if you pick a day greater than 12 you would see that error. You need to recofigure the `$.validator` to validate dates based on your `dd/MM/yyyy` format. –  Nov 24 '17 at 04:54

0 Answers0