data loading was blocked Select 2 yii2 - php

I worked with select2 widget and it works with a single, but when I put two select2 widget the second widget is blocked. I need your help please.
this is my select2 code:
<?= $form->field($model, 'idClient')->widget(Select2::classname(), [
'data' => ArrayHelper::map(Client::find()->all(),'idClient','nom'),
'options' => ['placeholder' => 'Selectionée le Client ...'],
'pluginOptions' => [
'allowClear' => true
],
]); ?>
<?= $form->field($model, 'idDevis')->widget(Select2::classname(), [
'data' => ArrayHelper::map(Devis::find()->all(),'idDevis','reference'),
'options' => ['placeholder' => 'Selectionée le Devis ...'],
'pluginOptions' => [
'allowClear' => true
],
]); ?>
the result is like that :

Related

How do I set template and labelOptions for Select2?

How to set my template and labelOptions in Select2 in Yii2? For a regular field, this can be done via field->labelOptions and field->template. And how to do it for Select2?
$form->field($model, 'test',[
'labelOptions' => ['style' => 'display:none !important;'],
'template' => '{label}{input}{error}'])
->radioButtonGroup($data, ['itemOptions' => ['class' => 'btn btn-default', 'style' => 'display:none !important;']
]); ?>
Select2, which is in question: https://demos.krajee.com/widget-details/select2
I asked the question himself and answered it himself, and even in the question itself. It was enough to do as in the example from the question - set field->template and field->label Options as needed:
$form->field($model, 'test', [
'template' => '{label}{input}{error}'
])->widget(Select2::classname(), [
'data' => $data,
'pluginOptions' => [
'allowClear' => true
],
]);

Kartik Select2 load ajax when other input change value

I need to load data with ajax to a Kartik Select2 but only when certain input changes values. Kind of like...
<?= $form->field($model, 'id_list')->widget(Select2::classname(), [
'data' => [],
'theme' => Select2::THEME_BOOTSTRAP,
'options' => [
'placeholder' => 'List',
],
'pluginOptions' => [
'allowClear' => true,
'action' => '#input_first'.change // or something
'ajax' => [
'url' => Url::to(['/list']),
'dataType' => 'json',
'data' => new JsExpression('function(params) { return {q:params.term}; }')
],
],
]);?>
Have you tried to use Select2 with DepDrop plugin (http://demos.krajee.com/widget-details/depdrop)?

Yii2 not showing error message on dropdownList

I created a dropdownList for my project and I made the field as required in my model rules.
In view
use app\models\Constituency;
use yii\helpers\ArrayHelper;
use kartik\widgets\Select
<?php
$constituency=Constituency::find()->all();
$listData=ArrayHelper::map($constituency,'constituency','constituency');
?>
<?php
echo '<label class="control-label">Constituency</label>';
echo Select2::widget([
'model' => $model,
'attribute' => 'place',
'data' => $listData,
'options' => ['placeholder' => 'Select a constituency'],
'pluginOptions' => [
'allowClear' => true
],
]);
?>
In Models
['place', 'required','message'=>'Place is required'],
Even I tired to give a custom error message for the field,But everything I tried was failed.
I am attaching the screenshot of the page here.
As you can see its shows no required error.
Can anyone tell me what I am missing??
Use active field widget:
<?= $form->field($model, 'place')->widget(Select2::className(), [
'data' => $listData,
'options' => ['placeholder' => 'Select a constituency'],
'pluginOptions' => ['allowClear' => true],
]) ?>

Yii2 required validation rule on "select2" widget

I'm using kartik select2 widget in Yii2 framework. Required validation rule doesn't work on it.
Here is my view code:
$form->field($model, 'city')->widget(\kartik\select2\Select2::classname(), [
'data' => $cities,
'options' => [
'class' => 'form-control',
'placeholder' => 'Please select city...',
'multiple' => false,
],
'pluginOptions' => [
'allowClear' => true
],
])->label('City');
Here is my model rule code:
[['city'], 'required'],
[['city'], 'integer']
Any idea to make the dropdown required?
Use this in plugin option
pluginOptions' => [
'initialize' => true,
],
This is working code for me
$form->field($model, 'tech_type')->widget(Select2::classname(), [
'options'=>['id'=>'tech-id'],
'data' => ArrayHelper::map(Techtypes::find()->asArray()->all(), 'tech_id', 'tech_type'),
'pluginOptions'=>[
'initialize' => true,
'placeholder' => 'Select Technician Type ...',
]
]);

Yii2 kartik datepicker multiple inline

I want a Datepicker inline with multidate enabled.
It is rendered correctly but returns only the last selected date.
Return value: '12.11.2016'
If I set 'type' to TYPE_INPUT everything is working fine.
Expected return Value: '23.11.2016, 24.11.2016, 18.11.2016, 12.11.2016'
<?= $form->field($model, 'dateString')->widget(DatePicker::className(), [
'type' => DatePicker::TYPE_INLINE,
'pluginOptions' => [
'multidate' => true,
],
]);
?>
I'm using "kartik-v/yii2-widget-datepicker": "#dev" and the model is a ActiveRecord Model.
Seems to have been fixed with this commit: https://github.com/kartik-v/yii2-widget-datepicker/commit/39e0e71277d0f115341e118a2b879a0dfcbd01c3
This will solve the problem
echo $form->field($model, 'date_time')->widget(DatePicker::classname(), [
'options' => [
'value' => "Jul-11-2020,Jul-14-2021,Jul-12-2020",
'class' => "col-md-12 form-control picker"
],
'readonly' => false,
'language' => 'en',
'type' => DatePicker::TYPE_INLINE,
'pluginOptions' => [
'format' => 'M-dd-yyyy',
'todayHighlight' => true,
'multidate' => true,
],
]);

Categories