Problem using kartik datepicker and select2 together

Hi,
i am using extension from kartik DatePicker and Select2. The problem is when user want to choose data from select2, widget datepicker also open (dropdown) too.
I don’t know what’s wrong. Please advice. thanks before.

here is my simple code.

<?php

use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\date\DatePicker;

/* @var $this yii\web\View */
/* @var $model app\models\Panjar */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="panjar-form">

    <?php $form = ActiveForm::begin(); ?>    

    <?= $form->field($model, 'dp_date')->widget(DatePicker::class,
                [
                    'type' => DatePicker::TYPE_COMPONENT_APPEND,
                    'value' => date('Y-m-d'),
                    'pluginOptions' => [
                        'autoclose' => true,
                        'format' => 'yyyy-mm-dd'
                    ]
                ]) ?>

    <?= $form->field($model, 'agen_id')->widget(kartik\select2\Select2::class, [
                    'data' => ArrayHelper::map(\app\models\Agen::findAll(['listed' => true]), 'id', 'name'),
                    'options' => ['placeholder' => 'Select Agen'],
                    'pluginOptions' => [
                        'allowClear' => true,
                    ],
                ]
            ) ?>

    <?= $form->field($model, 'total')->widget(\yii\widgets\MaskedInput::class,
            [
                'clientOptions' => [
                    'alias' => 'numeric',
                    'groupSeparator' => ',',
                    'digits' => 0,
                    'autoGroup' => true,
                    'removeMaskOnSubmit' => true,
                    'rightAlign' => false,
                ]
            ]) ?>

    <?= $form->field($model, 'remark')->textarea(['rows' => 6]) ?>

    <?= $form->field($model, 'transfer')->checkbox() ?>

    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>

Sorry, I reverted it back to bootstrap4 and it solved the issue.
I think it was the compability.
thanks for the attention.

Few comments though:

  1. Do not set value in the field. Set that in the controller when creating model and let it retain the latest in case of validation failure et al
  2. Avoid findAll() in the drop down and use Model::find()->asArray()->all() instead to avoid creating model objects only to dump them. When you have big list it becomes an issue
  3. Use Yii::t('app', 'Create') instead of 'Create' to make your app translation ready.
3 Likes

ok. thanks alot for your tips.