jwaliszko / ExpressiveAnnotations

Annotation-based conditional validation library.
MIT License
351 stars 123 forks source link

ExpressiveAnnotations and JqueryUI Datepicker anomoly #158

Closed jwstemper closed 7 years ago

jwstemper commented 7 years ago

When I use the JQueryUI datepicker widget on a date field that was created with the following annotation the client side validation is not triggered until I click in some other field, return to the date field and then exit.

     [AssertThat("ResolutionDate<=Today()", ErrorMessage = "Resolution date can not be in the future.")]
     [AssertThat("ResolutionDate>=DateReceived", ErrorMessage = "Resolution date must be after the date received.")]
     [DataType(DataType.Date)]
      public DateTime? ResolutionDate { get; set; }

I'm assuming some sort of event is missed. Any ideas or fixes?

jwaliszko commented 7 years ago

I think you could try to encourage the datepicker to execute the field validation as soon as the date selection is performed, e.g.

$('.date').datepicker().on('change', function() {
    $(this).valid(); // validate immediately (not to be forced to unfocus the input field)
});

In the sample project (Home.cshtml view in particular) such an approach is used.