Using Calendar Date Selection in a Block

Anyone have any quick thoughts on how I might use the Date picker widget from the Calendar Event Add form in a custom block?

It looks like I need to use concreteDurationSelector but I can’t figure out how to get that working.

Also, Can anyone else verify that the Calendar Event Add Form only gives options for AM times?

Thanks in advance
C

Would this help:

Do you need it to connect to the calendar, or do you just need a date/time picker? If the latter, you can use the HTML date/time element through the form helper.

Thanks for the replies. I don’t need the calendar for what I am doing. I was hoping to tap into the functionality of the event dates where the beginning date selection would change the end date but I think I can figure that out separately.

I ran into an issue though with the Date Widget was not functioning properly when not logged in as admin. I tried on a fresh install of 9.2.0 and nothing. Turns out the JqueryUI was not loading even after including

$this->requireAsset('jquery/ui');

in the controller’s view() function.

Yesterday I found this though and it is working now.

Thank you chemmett

For fellow Googlers…
in a block’s view.php file

<?php
$app = \Concrete\Core\Support\Facade\Application::getFacadeApplication();
$dtfh = $app->make('helper/form/date_time'); 
?>

<label for="start"><?=t('Start Date')?></label>
<?=$dtfh->date('start', $start)?>

<label for="end"><?=t('End Date')?></label>
<?=$dtfh->date('end', $end)?>

And in the block’s controller.php file’s view function

public function view()
{
   $al = \Concrete\Core\Asset\AssetList::getInstance();
   $al->register('css', 'jquery/ui', 'css/jquery-ui.css');
   $al->register('javascript', 'jquery/ui', 'https://code.jquery.com/ui/1.13.2/jquery-ui.min.js', ['local' => false]);
   $al->registerGroup('jquery/ui', [
      ['javascript', 'jquery/ui'],
      ['css', 'jquery/ui']
   ]);
   $this->requireAsset('jquery/ui');
}

Hopefully this will help for others who run into the same situation.

Separately but much less important: the DatePicker runs a script that takes the selected date, formats it properly, and adds it to a hidden text input field. Is there a better way (and I am sure there is) to tap into that value besides doing a setTimeout to wait for the DatePickers script to finish? This is truly not C5 related so feel free to give this the silent treatment.

Thanks again for all your input.
C

1 Like

And of course it can’t be that simple…
When the page is in edit mode there is some weird conflict.
Added

if (!$c->isEditMode()) {

}

around the asset registration.

1 Like