[TYPO3-mvc] Validating Datetime field

Florian Rival contact at oktopuce.fr
Fri Jul 1 17:14:07 CEST 2016


Hi Douwe,

There is a DateTime converter 
(TYPO3\\CMS\\Extbase\\Property\\TypeConverter\\DateTimeConverter) called 
before entering the action, may be you can do something before it is 
converted in an initializeAction() see the example below that changes 
the date format in accordance with the one used in a form. You can also 
write your own converter if needed.
But it's strange, you should see an error message if the date is invalid.

     /**
      * Initialize action for create form
      */
     public function initializeCreateAction() {
         if (isset($this->arguments['date'])) {
             $this->arguments['date']
                 ->getPropertyMappingConfiguration()
->setTypeConverterOption('TYPO3\\CMS\\Extbase\\Property\\TypeConverter\\DateTimeConverter', 
\TYPO3\CMS\Extbase\Property\TypeConverter 
\DateTimeConverter::CONFIGURATION_DATE_FORMAT, 'd.m.Y H:i:s');
         }
     }

     /**
     * Create form
      *
      * @param \DateTime $date Date to valid
      * @return void
      */
     public function createAction($date) {

     }

Hope it helps,
Florian

Le 01/07/2016 16:30, Douwe Doornbos a écrit :
> Anybody? Do you need more info?
>
> Quote: Douwe Doornbos (doornbos) wrote on Tue, 17 May 2016 12:06
> ----------------------------------------------------
>> I have a form with a datetime field. The problem is that when i enter 
>> an invalid date f.e. 32-1-1990 it is converted to 1-2-1990, without 
>> giving an error message. How can I validate this?
>>
>> I tried adding my own validator with @validate. But the property has 
>> already been converted before entering my own validator.
>>
>> Is there an action in the controller available that i can use?
>>
>> Definition in domain class is:
>>
>> /**
>>  * datefield
>>  *
>>  * @var \DateTime
>>  */
>> protected $datefield= '';
>>
>>
>> Thank you in advance.
>>
>> Douwe.
>>
> ----------------------------------------------------
>
>
> _______________________________________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc



More information about the TYPO3-project-typo3v4mvc mailing list