Date Field in Custom Block

Permalink
Is it possible to create a "Date Field" in a custom block?

I am creating a site for a musician with a page showing tour dates. I'm hoping to just have a date-picker that they can use to select a date for their tours.

joemc
View Replies: View Best Answer
tallacman replied on at Permalink Reply
tallacman
Have you thought about a pre-made solution:http://www.concrete5.org/marketplace/addons/dojo-tour-dates/... ?
joemc replied on at Permalink Reply
joemc
I already have my block setup and working... the linked block still doesn't resolve my issue as it looks like the user would still have to manually type in the date in an input field.

I would like to just have a date selector that populates that field.
andrew replied on at Permalink Best Answer Reply
andrew
joemc replied on at Permalink Reply
joemc
Cool. That's exactly what I needed. I am having some issue with the "$dtt->translate" function to post the value into the database. I'm pretty sure I'm not using it correctly, as I get an error... but, I know I need to implement it somehow in order to format it correctly.

This is what I have so far:

<?php
defined('C5_EXECUTE') or die(_("Access Denied."));
$dtt = Loader::helper('form/date_time');
?>
<label>Date</label>
<?php
$date = date("n/d/Y");
echo $dtt->date('tour_date', $date, true);
$dtt->translate('tour_date');
?>


Thanks for the help!
cherrycake replied on at Permalink Reply
cherrycake
Another solution would be to use use jquery's datepicker (http://jqueryui.com/demos/datepicker/)?

i don't think it's included in the jquery ui files in the C5 core so gohttp://jqueryui.com/download uncheck everything possible and only leave datepicker, widget, core and ui, then include them in your header..

then use
$('#tour_date').datepicker(dateFormat: 'yy-mm-dd');

and you should be good to go. seehttp://docs.jquery.com/UI/Datepicker/formatDate... for available formats.
andrew replied on at Permalink Reply
andrew
As of 5.4 datepicker is included in the core jquery.ui.js. All the files to run it should also be loaded when a page is in edit mode.

And translate() isn't used in the front-end. All you should have to use is the DateHelper::date() or DateHelper::datetime() methods. The translate() method is for taking a post and translating it back into a date string.
cherrycake replied on at Permalink Reply
cherrycake
good to know that it's included!
Shotster replied on at Permalink Reply
Shotster
Has anyone used jQuery date picker? I thought it made use of jQuery's dialog, so I wonder about any conflicts with C5's dialog.

-Steve
cherrycake replied on at Permalink Reply
cherrycake
pretty sure it doesn't. i think i've only used it in the dashboard and that worked fine, so the same should go for the front-end.
joemc replied on at Permalink Reply
joemc
Still using the form helper (I got rid of the 'translate')...

When I submit the form, the database field always ends up as "0000-00-00 00:00:00 ", so something isn't being formatted correctly as a date when it's sent.
joemc replied on at Permalink Reply
joemc
I ended up switching the database field type to VARCHAR instead of a DATE and it worked fine.