[TYPO3-mvc] Validation of non-mandatory DateTime fields

Henjo Hoeksma me at henjohoeksma.nl
Wed Apr 13 16:33:14 CEST 2011


On 2011-04-13 11:19:46 +0200, François Suter said:

> Any input on this?
> 
>> I stumbled on a weird behavior of the DateTime data type. Assuming I
>> declare a property as having to validate as a DateTime object, i.e.
>> 
>> /**
>> * Date and time of the doctor's examination
>> *
>> * @var DateTime $doctorDate
>> * @validate DateTime
>> */
>> protected $doctorDate;
>> 
>> If the date is wrong upon input (say somebody entered "xxxx"), I'll get
>> a validation error and the input form gets reloaded with an empty value
>> in the Date field. That's fine.
>> 
>> However if I leave the field empty (which is supposed to be fine,
>> because it's not mandatory) and the form gets reloaded because of some
>> other input error, the field is now filled with the current date, which
>> is not desirable. At which point in the process was the current date
>> "injected" into my property? Is there any way to prevent this?

This might be an issue with DateTime itself.
Perhaps you can force something different by giving it a default value 
of some whitespace - although that would be pretty nasty ...

Henjo



More information about the TYPO3-project-typo3v4mvc mailing list