我创建了表单更新并为启用按钮使用了一项功能。但是当我执行失败时。逻辑过程是当用户输入表单更新中的所有字段为“Ada”和“Lolos”(字段 wawancara)时,用户单击按钮变为启用状态。不知道为什么,请给我建议。
这段代码在视图中:
<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use yii\widgets\Pjax;
use yii\bootstrap\Modal;
use yii\helpers\Url;
use yii\db\ActiveRecord;
use yii\helpers\ArrayHelper;
use app\models\Calon;
use kartik\widgets\Select2;
?>
<h1 align="center">Form Ubah Ketentuan</h2>
<?php
echo " ";
echo " ";
?>
<?php $form = ActiveForm::begin([
'layout' => 'horizontal',
'enableAjaxValidation' => false,
'id' => 'update-form',
]);
?>
<?php
$data = ArrayHelper::map(Calon::find()->all(), 'kode_calon', 'nama_calon');
echo $form->field($model, 'kode_calon')->widget(Select2::classname(), [
'data' => $data,
'model' => $model,
'language' => 'id',
'disabled' => true,
'options' => [
'placeholder' => 'Pilih',
'id' => 'kode_calon'],
'pluginOptions' => [
'allowClear' => false,
'width' => '300px',
],
])->label('Calon nama anak asuh');
?>
<?php
echo $form->field($model, 'rapor')->widget(Select2::classname(), [
'model' => $model,
'hideSearch' => true,
'data' => ['Ada' => "Ada", 'Tidak' => "Tidak"],
'language' => 'id',
'options' => [
'placeholder' => 'Pilih',
'id' => 'rapor'],
'pluginOptions' => [
'allowClear' => false,
'width' => '380px',
],
])->label('Rapor');
?>
<?php
echo $form->field($model, 'ijazah')->widget(Select2::classname(), [
'model' => $model,
'hideSearch' => true,
'data' => ['Ada' => "Ada", 'Tidak' => "Tidak"],
'language' => 'id',
'options' => [
'placeholder' => 'Pilih',
'id' => 'ijazah'],
'pluginOptions' => [
'allowClear' => false,
'width' => '380px',
],
])->label('Ijazah');
?>
<?php
echo $form->field($model, 'surat_kematian_ortu')->widget(Select2::classname(), [
'model' => $model,
'hideSearch' => true,
'data' => ['Ada' => "Ada", 'Tidak' => "Tidak"],
'language' => 'id',
'options' => [
'placeholder' => 'Pilih',
'id' => 'surat_kematian_ortu'],
'pluginOptions' => [
'allowClear' => false,
'width' => '380px',
],
])->label('Surat kematian orang tua');
?>
<?php
echo $form->field($model, 'surat_keterangan_sehat')->widget(Select2::classname(), [
'model' => $model,
'hideSearch' => true,
'data' => ['Ada' => "Ada", 'Tidak' => "Tidak"],
'language' => 'id',
'options' => [
'placeholder' => 'Pilih',
'id' => 'surat_keterangan_sehat'],
'pluginOptions' => [
'allowClear' => false,
'width' => '380px',
],
])->label('Surat keterangan sehat');
?>
<?php
echo $form->field($model, 'akte_kelahiran')->widget(Select2::classname(), [
'model' => $model,
'hideSearch' => true,
'data' => ['Ada' => "Ada", 'Tidak' => "Tidak"],
'language' => 'id',
'options' => [
'placeholder' => 'Pilih',
'id' => 'akte_kelahiran'],
'pluginOptions' => [
'allowClear' => false,
'width' => '380px',
],
])->label('Akte kelahiran');
?>
<?php
echo $form->field($model, 'kartu_keluarga')->widget(Select2::classname(), [
'model' => $model,
'hideSearch' => true,
'data' => ['Ada' => "Ada", 'Tidak' => "Tidak"],
'language' => 'id',
'options' => [
'placeholder' => 'Pilih',
'id' => 'kartu_keluarga'],
'pluginOptions' => [
'allowClear' => false,
'width' => '380px',
],
])->label('Kartu keluarga');
?>
<?php
echo $form->field($model, 'foto')->widget(Select2::classname(), [
'model' => $model,
'hideSearch' => true,
'data' => ['Ada' => "Ada", 'Tidak' => "Tidak"],
'language' => 'id',
'options' => [
'placeholder' => 'Pilih',
'id' => 'foto'],
'pluginOptions' => [
'allowClear' => false,
'width' => '380px',
],
])->label('Foto');
?>
<?php
echo $form->field($model, 'surat_pengantar_rt_rw')->widget(Select2::classname(), [
'model' => $model,
'hideSearch' => true,
'data' => ['Ada' => "Ada", 'Tidak' => "Tidak"],
'language' => 'id',
'options' => [
'placeholder' => 'Pilih',
'id' => 'surat_pengantar_rt_rw'],
'pluginOptions' => [
'allowClear' => false,
'width' => '380px',
],
])->label('Surat pengantar RT RW');
?>
<?php
echo $form->field($model, 'surat_rek_muh')->widget(Select2::classname(), [
'model' => $model,
'hideSearch' => true,
'data' => ['Ada' => "Ada", 'Tidak' => "Tidak"],
'language' => 'id',
'options' => [
'placeholder' => 'Pilih',
'id' => 'surat_rek_muh'],
'pluginOptions' => [
'allowClear' => false,
'width' => '380px',
],
])->label('Surat rekomendasi Muhammadiyah');
?>
<?php
echo $form->field($model, 'wawancara')->widget(Select2::classname(), [
'model' => $model,
'hideSearch' => true,
'data' => ['Lolos' => "Lolos", 'Tidak' => "Tidak"],
'language' => 'id',
'options' => [
'placeholder' => 'Pilih',
'id' => 'wawancara',
],
'pluginOptions' => [
'allowClear' => false,
'width' => '380px',
],
])->label('Wawancara');
?>
<?php
echo $form->field($model, 'surat_ketersediaan_anak')->widget(Select2::classname(), [
'model' => $model,
'hideSearch' => true,
'data' => ['Ada' => "Ada", 'Tidak' => "Tidak"],
'language' => 'id',
//'disabled' => true,
'options' => [
'placeholder' => 'Pilih',
'id' => 'surat_ketersediaan_anak',
],
'pluginOptions' => [
'allowClear' => false,
'width' => '380px',
],
])->label('Surat ketersediaan anak');
?>
<?php
echo $form->field($model, 'surat_pernyataan_wali')->widget(Select2::classname(), [
'model' => $model,
'hideSearch' => true,
'data' => ['Ada' => "Ada", 'Tidak' => "Tidak"],
'language' => 'id',
//'disabled' => true,
'options' => [
'placeholder' => 'Pilih',
'id' => 'surat_pernyataan_wali',
],
'pluginOptions' => [
'allowClear' => false,
'width' => '380px',
],
])->label('Surat pernyataan wali');
?>
<?= $form->field($anak_asuh, 'kode_anak_asuh')->hiddenInput(['readOnly' => true, 'style' => 'width:100px'])->label(false); ?>
<?php
$anak_asuh->kode_calon = $model->kode_calon;
?>
<?= $form->field($anak_asuh, 'kode_calon')->hiddenInput(['style' => 'width:100px'], ['disabled' => true])->label(false); ?>
<?= $form->field($anak_asuh, 'status')->hiddenInput(['style' => 'width:380px', 'value'=>'Tetap'], ['disabled' => true])->label(false); ?>
<div class="form-group">
<div class="col-sm-offset-4">
<?= Html::submitButton('Ubah', ['class' => 'btn btn-primary', 'disabled' => 'disabled', 'id' => 'ubah']) ?>
<?php
echo " ";
echo " ";
echo Html::a('Keluar', ['index'],[
'class'=>'btn btn-success',
'onclick' =>'$("#ketentuanModal").modal("hide");
return false;'
]);
?>
<?php ActiveForm::end();?>
<?php // This function
$this->registerJs('
$("#rapor, #ijazah, #surat_kematian_ortu, #surat_keterangan_sehat, #akte_kelahiran, #kartu_keluarga, #foto, #surat_pengantar_rt_rw, #surat_rek_muh, #wawancara, #surat_ketersediaan_anak, #surat_pernyataan_wali").on("change",function(){
var isi1 = this.value;
var isi2 = this.value;
var isi3 = this.value;
var isi4 = this.value;
var isi5 = this.value;
var isi6 = this.value;
var isi7 = this.value;
var isi8 = this.value;
var isi9 = this.value;
var isi10 = this.value;
var isi11 = this.value;
var isi12 = this.value;
if(isi1 == "Ada" && isi2 == "Ada" && isi3 == "Ada" && isi4 == "Ada" && isi5 == "Ada" && isi6 == "Ada" && isi7 == "Ada" && isi8 == "Ada" && isi9 == "Ada" && isi10 == "Lolos" && isi11 == "Ada" && isi12 == "Ada") {
$("#ubah").attr("disabled",false);
}
});
')
?>