I'm using Activeform and I need a custom field to insert datetime values.
I've found a possible solution myself with kartik DateTimePicker although it is much more complex than I wanted, anyway I don't know how to put the value in the model's attribute.
use kartik\datetime\DateTimePicker;
<?php $form = ActiveForm::begin(); ?>
// my working field using kartik library
<?= $form->field($model, 'course')->widget(\kartik\select2\Select2::className(),[
'data' => $data,
'language' => 'it',
'options' => ['placeholder' => 'Select a Course ...'],
'pluginOptions' => [
'allowClear' => true
],
]);?>
// the field I need to implement placing the result in $form->field($model, 'opening_date')
<?php //echo '<label style="position:absolute; top:5px; text-align:left;">Recording Time</label>';
echo '<label>Start Date/Time</label>';
echo DateTimePicker::widget([
'name' => 'opening_date',
'options' => ['placeholder' => 'Select operating time ...'],
'convertFormat' => true,
'pluginOptions' => [
'format' => 'd-M-Y g:i A',
'startDate' => '01-Mar-2014 12:00 AM',
'todayHighlight' => true
]
]);
?>
I accept also solutions offering a simpler way to show the field.