當我嘗試在模態中使用kartik select2插件時,下拉不會顯示。當我沒有模態地使用它時,它就像魅力一樣。 這是從插件網站採取相同的代碼,但它仍然無法正常工作。我已經在通過選擇2插件CSS和JS們並未從資產文件加載瀏覽器生成的源代碼中發現yii2 kartik select2插件無法在模態中工作
Modal::begin([
'header' => '<h1>Assign Applicant</h1>',
'options' => [
'id' => 'assignApplicantModal',
'tabindex' => false
],
]);
?>
<div class="job-positions-form">
<?php
$form = ActiveForm::begin();
?>
<div class="row">
<div class="col-sm-12">
<div class="col-sm-6">
<?php
$data = ArrayHelper::map(Applicant::find()->where('status = :status', [':status' => 'Active'])->all(), 'id', function($model) {
return $model->first_name . ' ' . $model->last_name;
});
echo $form->field($assign_model, 'applicant_id')->widget(Select2::classname(), [
'data' => $data,
'attribute' => 'applicant_id',
'options' => ['placeholder' => 'Select an applicant'],
'pluginEvents' => [
"select2:selecting" => "function() { "
. "no_position = $('body').data('no_position');"
. "if(no_position>= " . $model->no_of_persons . "){alert('You can select only " . $model->no_of_persons . " applicant(s)');return false;} }",
"select2:select" => "function() { "
. "no_position = $('body').data('no_position');"
. "$('body').data('no_position',++no_position);}",
"select2:unselect" => "function() { "
. "no_position = $('body').data('no_position');"
. "$('body').data('no_position',--no_position);}",
]
]);
?>
</div>
<div class="col-sm-6">
<?php echo $form->field($assign_model, 'applicant_pay')->textInput(['maxlength' => true]); ?>
</div>
<div class="form-group" style="text-align: center;">
<?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
</div>
</div>
<?php ActiveForm::end(); ?>
</div>
<?php
$inlineScript = "$('body').data('no_position'," . count($applicant_id) . ")";
$this->registerJs($inlineScript, \yii\web\View::POS_END, 'my-inline-js');
Modal::end();
HTML:
<div id="assignApplicantModal" class="fade modal" role="dialog">
<div class="modal-dialog ">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h1>Assign Applicant</h1>
</div>
<div class="modal-body">
<div class="job-positions-form">
<form id="w0" action="/staffing/scheduler/web/scheduler/assign_applicant" method="post">
<input type="hidden" name="_schedulerCSRF" value="eEI4TnpSZWcaFnYWNQQcKx0ndC8VEVUyDAl6LAgfBzUTKQw3EBAEEg
=="> <div class="row">
<div class="col-sm-12">
<div class="col-sm-6">
<div class="form-group field-assignapplicant-applicant_id required">
<label class="control-label" for="assignapplicant-applicant_id">Applicant</label>
<div class="kv-plugin-loading loading-assignapplicant-applicant_id"> </div><select id="assignapplicant-applicant_id"
class="form-control" name="AssignApplicant[applicant_id]" data-s2-options="s2options_d6851687" data-krajee-select2
="select2_86691c6a" style="display:none">
<option value="">Select an applicant</option>
<option value="12">ASD</option>
<option value="13">qwe</option>
<option value="14">zxc</option>
</select>
<div class="help-block"></div>
</div> </div>
<div class="col-sm-6">
<div class="form-group field-assignapplicant-applicant_pay required">
<label class="control-label" for="assignapplicant-applicant_pay">Applicant Pay</label>
<input type="text" id="assignapplicant-applicant_pay" class="form-control" name="AssignApplicant[applicant_pay
]">
<div class="help-block"></div>
</div> </div>
<div class="form-group" style="text-align: center;">
<button type="submit" class="btn btn-primary">Update</button> </div>
</div>
</div>
</form></div>
</div>
</div>
</div>
</div>
你檢查輸出HTML的樣子? – Dekel
@Dekel我已經放置了HTML的圖像。請檢查 – Ish
我們不需要圖片,我們需要html。不可能通過查看圖像來了解html代碼的外觀:) – Dekel