Date as property type not working

Hello everyone,

I want to create a new object with the property “creationDate”. In my form I wrote:

<f:form.textfield type="date" property="creationDate" />

However, this leads to the following error:

Notice: Array to string conversion in /var/www/public/Data/Temporary/Development/Cache/Code/Flow_Object_Classes/TYPO3Fluid_Fluid_Core_ViewHelper_TagBuilder.php line 199

Exception Code 1
Exception Type Neos\Flow\Error\Exception
Log Reference 20201024142634f1884c
Thrown in File Packages/Framework/Neos.Flow/Classes/Error/ErrorHandler.php
Line 81

If I pass the date as string separately to createAction and then convert it to a DateTime, it works.

Is there a way to avoid this detour?

Thanks for your help!

Best regards,

Tobias

Use value="{createionDate -> f:format.date(format: '...')} to tell fluid how to render the value of the object

I believe this post here can help you on using the TypeConverter to convert form input to a DateTime object

https://sandstorm.de/de/blog/post/neos-snippets-1-datetime-attributes-and-html5-input-elements.html

Dear Søren,

thank you very much for your help. The solution with the “initializeCreateAction” works for me - it’s just some very much code to make a DateTime out of a string. Passing the property creationDate manually to the createAction and convert it into a DateTime seems to be faster.

Nevertheless I found your link very interesting, because I learned that browsers pass different Date strings - which makes it even more uncomfortable.

Sure it seems like a lot of code for very little :slight_smile:

The idea of the propertymapper configuration, is to tell Flow, what format the data is passed as (Y-m-d for ex.) so it can convert it to the data object you expect in your actual createAction :slight_smile: In that way, you always gets a DateTime object in your action, so you don’t have to convert it inside the action :slight_smile:

I hope you get on with your project - if you get any new questions, create a new thread and let’s solve it :slight_smile:

Little addendum: You can achieve the same without the initialize*Action and PropertyMappingConfiguration, by including the format in the form data like so:

<f:form object="{appointment}" objectName="appointment" action="create" method="POST" controller="Appointment">  
    <f:form.textfield type="datetime-local" property="startDate.date" value="{startDate ->  f:format.date(format:'Y-m-d\TH:i')}" id="startDate" additionalAttributes="{step:'900'}"/>
    <f:form.hidden property="startDate.dateFormat" value="Y-m-d\TH:i" />  
    <f:form.submit value="Send" />
</f:form>

Yes, the property “startDate” does not have the subproperties “date” and “dateFormat”, but that is not important. The ViewHelper just uses this as a path to a form field name without checking the property as long as the “value” attribute is also given. As the form data will be submitted as an array of values and the DateTimeConverter can convert an array with values date and dateFormat into a DateTime object. With this, you can even make the date format dynamic in the browser, by changing the value of the dateFormat field.

3 Likes

Holy moly - that is clever stuff! :star_struck: I have never been aware of this possibility and idea! That is yet another gem :gem:

This is indeed a really elegant solution. It works perfectly for me. Thank you very much!