Closed
Description
Hi there,
At work we wanted to check if a date (in a form) was greater than "now". The problem was that we were using annotations in our entity for the validation and (apparently) there is no "simple" way to do so.
The solutions which came to my mind were:
- Use the "assert greater than" validator directly in the form type (
$builder->add('foo', 'bar', array('constraints' => new \DateTime())
) - Use the annotation
@Assert\True
on my date field and implement anisDateValid
method - Create a dedicated annotation
- Create an
@DateTime
annotation which would extends from\DateTime
and could be used everywhere (in my case :@Assert\GreaterThan(value = @DateTime)
)
I've chosen to implement the latest of my proposal (@DateTime
), it works well (IMO it is flexible, clean and reusable) and I think it could be a very good idea to implement it in symfony.
What do you think about it?
If you feel like it, I can share my work.