Calendar picker troubles


#1

Hello, I’d like to date picker to w work straight from the model and use the “Y-m-d H:i” datetime format.

I was experimenting a lot, in example:
$this->addField(‘gc_event_datetime’, [‘type’=>‘datetime’],[‘Calendar’,options=>[“ampm”=>false, “firstDayOfWeek” => 1,“today” => true]]);

Could anyone help please - I have spend a few hours trying to win with the calendar picker already… :frowning:

Great thanks to all the good people who will try to help. :slight_smile:


#2

Hi Simpo.

It’s acutally possible like this:

$this->addField('gc_event_datetime', [
    'type'=>'datetime', 
    'ui'=>['form'=>[
        'Calendar', 
         'options'=>['ampm'=>false]
   ]]
]);

I haven’t tested it, but you basically explicitly specify which object to use through a ‘ui’ property.

Here is the example I was able to find:


#3

@romaninsh it works! :slight_smile: Thank you, you have no idea how frustrating it was. :slight_smile:

But… there is another issue, the calendar returns date like “March 14, 2018 9:20” what is inconsistent with defined “Y-m-d H:i”, so the form validation returns an error “Incorrectly formatted datetime”. Is there a way to define format of the datetime returned by picker ?


#4

To be honest, i’m not so familiar with the picker itself. It’s job is to put date into a field, which is then parsed by PHP.

The data conversions are done through a process called type-casting (if you need to go deeper, it’s here See: http://agile-data.readthedocs.io/en/develop/typecasting.html)

So ATK sees form as a sort of temporary data storage. We call it UI persistence, we give data to user he can enter it back.

UI persistence is accessible under app->ui_persistence and you can change those formats. They are global, though, but you can probably think of something.

There is also process called normalization, which invoked for date fields here: https://github.com/atk4/data/blob/develop/src/Field.php#L329.

Hope this can send you in the right direction. :sunny:


#5

Here is example on how to set custom UI persistence:

http://agile-ui.readthedocs.io/en/latest/type-presentation.html?highlight=persistence#display-card-number-with-spaces


#6

Thanks!

Unfortunately I’m unable to have a working datetime picker. :frowning:

I’m setting:

$app->ui_persistence->datetime_format = 'Y-m-d H:i:s';
$app->ui_persistence->date_format = 'Y-m-d';
$app->ui_persistence->time_format = 'H:i:s';

Then in the model:

$this->addField('gc_event_datetime', [
                'type'=>'datetime', 
                'ui'=>[
					'datetime_format' => 'Y-m-d H:i:s',
					'date_format' => 'Y-m-d',
					'time_format' => 'H:i:s',
					'form'=>[
                'Calendar',
					'type'=>'datetime',
                'options'=>['ampm'=>false,'firstDayOfWeek' => 1],
                ]]
                ]);

No luck, I’m unable to have a working calendar widget. :frowning:


#7

May need some debugging. I haven’t really had a chance to use custom date formats yet. We certainly need fixed. If you clean this up and put entire example on a single page (like in demos/*) then open a ticket on github, someone could take a look. I’m a bit busy with some client-work at the moment.