Daniel Pineault
asked on
Apply datetime formatter to form field
Using Yii2, I'm trying to apply a format to a Datetime field/control
I set the formatter in my config file, but it doesn't seem to do anything?!
I believe this is basically what I need to do
No matter what I do, I always have seconds displayed and I only want hour and minutes
could someone either point out what I'm doing wrong with the config file or how I can specify the formatter to the $form->field().
Thank you for the helping hand.
echo $form->field(
$modelLeg,
"[{$i}]StartDt",
[
'options' => ['class' => 'table-control'],
'template' => '<div class="">{input}</div>'."\n".'<div class="">{hint}{error}</div>'
]
)
->widget(
DateTimePicker::className(), [
'type' => DateTimePicker::TYPE_INPUT,
'pluginOptions' => [
'autoclose'=>true,
'format' => 'yyyy-mm-dd hh:ii',
'todayHighlight' => true,
]
]
);
I set the formatter in my config file, but it doesn't seem to do anything?!
'formatter' => [
'class' => 'yii\i18n\Formatter',
'dateFormat' => 'yyyy-MM-dd', //'php:Y-m-d',
'timeFormat'=>'HH:mm', //php:H:i',
'datetimeFormat'=>'yyyy-MM-dd HH:mm', //'php:Y-m-d H:i',
'currencyCode' => '$',
'decimalSeparator' => '.',
'thousandSeparator' => ',',
],
I believe this is basically what I need to do
echo $form->field(
$modelLeg,
"[{$i}]StartDt",
[
'options' => ['class' => 'table-control'],
// 'inputOptions' => ['enableLabel' => false,]
// 'inputOptions' => ['value' => \Yii::$app->formatter->asDatetime($modelLeg->StartDt, 'M/d/Y')],
'template' => '<div class="">{input}</div>'."\n".'<div class="">{hint}{error}</div>',
]
)
but it doesn't work and I think this has to do with the dynamic form attribute not being StartDt but rather [{$i}]StartDt. However, I can't get it to accept any of the variations I've attempted.No matter what I do, I always have seconds displayed and I only want hour and minutes
could someone either point out what I'm doing wrong with the config file or how I can specify the formatter to the $form->field().
Thank you for the helping hand.
ASKER
There are no error or other issues being reported in the console or debugger.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
and in browser right click inspect / console for errors