0
votes

I've added 2amigos datepicker for Yii2 (https://github.com/2amigos/yii2-date-picker-widget) to my form.

However the datepicker is rendered a few lines above the actual input field, as seen in the screenshot below:

enter image description here

The datepicker should be displayed just above the "Create time" field. I've also tried Kartik's DatePicker, same results.

My code is:

<?php

use dosamigos\datepicker\DatePicker;

    <?= $form->field($model, 'create_time')->widget(DatePicker::className(), [
        'template' => '{input}{addon}',
        'clientOptions' => [
            'autoclose' => true,
            'format' => 'yyyy-mm-dd'
        ]
    ]) ?>

The rest of the form is generated with Yii2 CRUD generator.

3
Have you tried making sure its not a styling issue? Maybe bootstraps messing it up? Are they in the same container/row? - ddsbro
are you using 3rd party bootstrap theme ? - Michael Nguyen
I'm using bootstrap from yiisoft, "yiisoft/yii2-bootstrap": "*", - user2910789

3 Answers

0
votes

Try using the widget in this manner:

<?php echo '<label class="control-label">Create Time</label>'; ?>
<?= DatePicker::widget([
    'attribute' => 'create_time',
    'model' => $model,
    //'language' => 'ru',
    'dateFormat' => 'dd-MM-yyyy',
    ]) ?>

Hope this helps.

0
votes

Try with inline => true:

<?= $form->field($model, 'create_time')->widget(DatePicker::className(), [
    'template' => '{input}{addon}',
    'inline' => true, 
    'clientOptions' => [
        'autoclose' => true,
        'format' => 'yyyy-mm-dd'
    ]
]) ?>

For more Configuration option.

0
votes

I also faced this issue. Check for any margin-top attribute that is applied to the body and change it to padding-top

body {
  color: #73879C;
  background: #fff;
  font-family: "Helvetica Neue", Roboto, Arial, "Droid Sans", sans-serif;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.471;
  /*margin-top: 58px;*/
  padding-top: 58px;
}

it will solve your issue!!!