-1

If someone would forget to put in the date and then click submit we would get "Date of Visit is required" as expected, but then after the date is populated the "required" message doesn't disappear as it does with every other field. I can still click submit and it works fine but the project owner feels this may confuse people and wants it to disappear as it is supposed to when the field is filled out properly. I have 1.16 of jQuery.Validation in my NuGet packages, there are no updates.

In my view I have this:

<div class="form-group">
    @Html.LabelFor(m => m.DateOfVisit, new { @class = "form-label" })
    @Html.TextBoxFor(m => m.DateOfVisit, new { @class = "form-control", type = "Date", placeholder = "MM/DD/YYYY", @Value = "" })
    @Html.ValidationMessageFor(m => m.DateOfVisit, string.Empty, new { @class = "text-danger" })
</div>

In my model I have this

[Required(ErrorMessage = "Date of Visit is required")]
[DataType(DataType.Date)]
[Display(Name = "Date of Visit")]
public DateTime DateOfVisit { get; set; }

Edit: This happens, on, I assume all browsers. I duplicated the issue on Chrome and IE 11. Also, it is only the one field that is behaving this way; the "required" text goes away on all the other fields. I don't know why this one is different.

Sparky
  • 98,165
  • 25
  • 199
  • 285

1 Answers1

0

I'm not sure if it is an answer but more of a work around just so I can move on

Having a css hidden that basically does 'display: none' I hid the warning text on blur.

$('#DateOfVisit').blur(function() {
    if ($(this).val()) {
        $('#DateOfVisit-error').addClass('hidden');
    }
    else {
        $('#DateOfVisit-error').removeClass('hidden');
    }
});

Hope it helps someone else until they officially fix it. Again I have version 1.7.