[Flow] Validation > Exception instead of going back to newAction
Bastian Waidelich
bastian at typo3.org
Thu Dec 5 14:29:53 CET 2013
Axel Wüstemann wrote:
Hi again,
>>> I put the createAction and the newAction to pastebin
>>> http://pastebin.com/0M5e1Qr8
>>
>> Ok, this is what happens (I believe):
>> You submit the form and the $depositInspection is passed to the
>> createAction. But it can't be validated [...]
> This seems to be the case - how this could be solved?
Well that's easy: Remove the @Flow\Validate(type="NotEmpty") annotation
from the date property of your model or make sure it is set in the
instance that is passed to the createAction.
I guess, you don't want to remove the validate annotation ;)
If "date" refers to the creation-date of the instance, you could just
set it in the constructor (which is never called again).
If it should be settable by the user, you can make use of the
DateTimeConverter[1]. That allows you to set time, date and timezone
individually (maybe the DatePicker of the Form package[2] is a good
inspiration).
If you really want to set the date in the controller, you can do so in a
(protected) initializeCreateAction() that is called before the
createAction():
protected function initializeCreateAction() {
$depositInspection = $this->arguments->getArgument('depositInspection');
if ($depositInspection !== NULL) {
$depositInspection->setDate(...);
}
}
> I will try do digger into the code, hoperfully I will find a solution.
> The customer wanted to hava this splitted date / time fields.
>
> the new form
> http://pastebin.com/5z1Drdvd
It should work directly if you replace
<f:form.textfield name="__date" ...
and
<f:form.textfield name="__time" ...
by
<f:form.textfield property="date.date" ...
and
<f:form.textfield property="date.hour" ... <f:form.textfield
property="date.minute" ...
and a hidden field with the expected date format:
<f:form.hidden property="date.dateFormat" value="dd.mm.yy" />
Or you encapsulate that into ViewHelpers as it's done exemplary in the
form framework[3].
>> Out of curiosity: why do your repositories have *AsOptions() methods?
>> And what does __buildDateTime() do?
>
> - asOptions() delivers arrays to fill selectBoxes
This is not required, the select ViewHelper can deal with arrays as well
as QueryResultInterface.
<f:form.select property="fast" options="{fasts}"
optionLabelField="the.title" prependOptionLabel="- select one -" />
HTH,
[1]
https://git.typo3.org/Packages/TYPO3.Flow.git/blob/HEAD:/Classes/TYPO3/Flow/Property/TypeConverter/DateTimeConverter.php
[2]
https://git.typo3.org/Packages/TYPO3.Form.git/blob/HEAD:/Resources/Private/Form/DatePicker.html
[3]
https://git.typo3.org/Packages/TYPO3.Form.git/blob/HEAD:/Classes/TYPO3/Form/ViewHelpers/Form/DatePickerViewHelper.php
&
https://git.typo3.org/Packages/TYPO3.Form.git/blob/HEAD:/Classes/TYPO3/Form/ViewHelpers/Form/TimePickerViewHelper.php
--
Bastian Waidelich
More information about the Flow
mailing list