formapro / JsFormValidatorBundle

The Javascript validation for Symfony 2, 3 and 4 forms
MIT License
128 stars 56 forks source link

Range constraint on date fields is always invalid #126

Open soerenbernstein opened 7 years ago

soerenbernstein commented 7 years ago

I have a symfony form which includes a DateType for a birthday field of my entity. The entity has an annotated Range constraint:

/**
  * @Assert\Range(
  *     max = "today",
  *     min = "first day of this month - 14 years UTC",
  */
  var $birthday;

This will work in symfony, but during client side validation, any date entered is invalid. Am I doing something wrong, or is this not supported?

66Ton99 commented 7 years ago

Yes, I think it is does not supported. Max and Min must be specific date.

soerenbernstein commented 7 years ago

Even with a specific date, this will not work because the js range constraint has some isNaN() test, which will fail on any date string. I've fiddled around with the code a bit and hack something that will allow dates to pass correctly, but only if the input field is of type "date". There are more issues, especially there is no way for the moment to remember the original (as in Symfony FormType) type of the field, so there is no distinction between DateTime, Date and Time.