I want to add single_datetime field to my custom API form.

I am trying to add the following code to my form, but not working properly

$form['dob'] = [
'#title' => 'Date of Birth',
'#type' => 'date',
'#attributes' => [
'data-hour-format' => '24h',
'data-allow-times' => '5',
'data-first-day' => '0',
'data-disable-days' => [],
'data-inline' => '0',
'data-datetimepicker-theme' => 'default',
'data-single-date-time' => 'datetime',
],
];

Please guide me , how to apply ?

Comments

selvakumar created an issue. See original summary.

selvakumar’s picture

I found the solution

$form['dob'] = [
'#title' => 'Date of Birth',
'#type' => 'textfield',
'#time' => TRUE,
'#weight' => -10,
'#attributes' => [
'data-hour-format' => '24h',
'data-allow-times' => '5',
'data-first-day' => '0',
'data-disable-days' => [],
'data-inline' => '0',
'data-datetimepicker-theme' => 'default',
'data-single-date-time' => 'datetime',
],
];
$form['#attached']['library'][] = 'single_datetime/datetimepicker';
$form['#attributes']['autocomplete'] = 'off';

$form['submit'] = [
'#type' => 'submit',
'#value' => 'Submit',
];

valic’s picture

Excellent example.

Will make addition to documentation.

valic’s picture

Assigned: Unassigned » valic

Update README

djmanas’s picture

Any more information? how to change format, etc? I am lost after change to drupal 8...

  • valic committed 07a3117 on 8.x-1.x
    Issue #2991040 by selvakumar, valic: How to use single_datetime in...

  • valic committed 714af9b on 8.x-1.x
    Issue #2991040 by selvakumar, valic: How to use single_datetime in...
valic’s picture

Status: Active » Fixed

updated docs, and added some examples inside the readme file
https://github.com/Vallic/single_datetime/blob/8.x-1.x/README.md

Also added few static functions with default attributes for examples, and easier c/p integration of default widget for non-dev people

@djamanas, if you have some additional support questions, please open a new issue.

valic’s picture

Status: Fixed » Closed (fixed)

Released in 1.7