Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Range constraint on date fields is always invalid #126

Open
soerenbernstein opened this issue Jun 29, 2017 · 2 comments
Open

Range constraint on date fields is always invalid #126

soerenbernstein opened this issue Jun 29, 2017 · 2 comments

Comments

@soerenbernstein
Copy link

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
Copy link
Collaborator

66Ton99 commented Jun 29, 2017

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

@soerenbernstein
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants