Has anyone figured out the 5.7 version of Loader::helper('form/date_time')?
PermalinkExample code that I am using:
I would like to add the ability to select a time like the date/time attribute in composer does.
Also, I know there is a move away from Loader functions, so I am interested in learning how to use the new 5.7 approach for this.
For clarity, I attached the date picker that I am currently getting in my block and the desired date time picker used in composer.
Thank you
These work as expected, I get the date picker and the values are stored.
<?php echo Core::make('helper/form/date_time')->date('tourDate', $tourDate); ?>
<?php echo Loader::helper('form/date_time')->date('tourDate', $tourDate); ?>
These supply the date time picker, but the picked values aren't being stored.
<?php echo Core::make('helper/form/date_time')->datetime('tourDate', $tourDate); ?>
<?php echo Loader::helper('form/date_time')->datetime('tourDate', $tourDate); ?>
The DateTime helper/service provides a "translate" method which allows you to fetch the correct selected value when using the date/time selector. You need to use that because the value comes from multiple fields if you include the time selector.
$tourDate = Core::make('helper/form/date_time')->translate('tourDate');
Your explanation of translate() makes sense, but I don't know how to use the example code you provided to create the date time picker or save the $tourDate.
I appreciate your patience. I am new to concrete5 and what I know is based on experimenting with exists blocks.
Here is the controller:
https://gist.github.com/anonymous/522903ba2676b1a71445...
Here is the form:
https://gist.github.com/anonymous/742e44123b93d1e081a9...
Based on what I linked to, is the issue that I need save arguments in my controller for $tourDate? Questions like these will soon be cleared up when the block documentation comes out.
Yes, you are correct that you need to override the save() method:
public function save($data) { $data['tourDate'] = Core::make('helper/form/date_time')->translate('tourDate'); parent::save($data); }
Also another point, in your db.xml you should use the 'T' type for date+time and 'D' type for only the date as described in the ADOdb docs:
http://phplens.com/lens/adodb/docs-datadict.htm...
While it might also work with the 'C' type it does not mean that it's correct. You should always use the correct type of a db field, that's what they are for. If you learn it the 'wrong' way the first time, you end up doing it that way also in the future.
Believe me, it will also help you in the future when you're doing something more complex.
That was a huge help and I will learn from it. I also bookmarked that page.
Excellent advice on using the right data type. I was originally using T, but changed it to C - thinking that maybe the format being sent needed to be converted first.
And if you want to include the time selector, change the "date" function name to "datetime".