Halo agan2 semua,
Saya Newbie di php Yii2, Sekarang saya lagi buat aplikasi Inventory menggunakan Yii2framworks,
cuma saat ini saya stack ada kendala. Yang saya maksud seperti berikut.
-
Saya buat sebuah Dropdown dari data tabel A (kode barang, nama barang) misalkan ditampilkan nama Barang.
-
Saat Dropdown itu dipilih datanya akan mengambil data di tabel B (isinya kode barang, lokasi dan jumlah) berdasarkan kode barang yang dipilih di Dropdown tsb,
-
Data yang diambil akan disimpan di 2 textbox, txtLokasi dan txtQuantity,
Pertanyaannya, bagaimana cara untuk membuat script langkah 2 dan 3.
Saya harap bantuan agan2 semua, Urgent pls.
Terima Kasih,
Iwan K
Ini contoh View nya
<div class="budgets-form">
<div class="container-fluid">
<?php
$form = ActiveForm::begin([
'id' => 'new-form',
'options' => ['class' => 'form-horizontal'],
'method' => 'post',
]);
?>
<div>
<div class="form-group">
<label class="control-label col-sm-2" for="fld_no">No. Circulait :</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="fld_no" name="fld_no" readonly value=" <?php echo $no ?> ">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="fld_pos">Posisi Baris :</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="fld_pos" placeholder="Posisi Baris" readonly name="fld_pos" value=" <?php echo $pos ?> ">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="fld_budget">Budget :</label>
<div class="col-sm-10">
<?php
echo Html::dropDownList('fld_budget', null, ArrayHelper::map(app\models\BudgetDetail::find()
->where('fld_status' . " = 'Active'")
->all(), 'fld_no', 'fld_deskripsi'), [
'prompt' => Yii::t('app', 'Pilih Budget...'),
'onChange' => '$.post( "' . Yii::$app->urlManager->createUrl(["/circulait/getbdgt", 'id' => '']) . '",function(data){$("#fld_bpos").val(data);})',
'id' => 'fld_budget',
'class' => 'dependent-input form-control',
'ajax' => [
'type' => 'POST',
'url' => Yii::$app->urlManager->createUrl(['/circulait/getbdgt', 'id' => Yii::$app->request->post()]),
'update' => '#fld_bpos',
'data' => ['fld_budget' => 'js:this.value'],
'success' => 'alert ("ok");'
]
]);
?>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="fld_bpos">Budget Line No. :</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="fld_bpos" placeholder="Budget Line No" name="fld_bpos">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="fld_jenis">Jenis Budget :</label>
<div class="col-sm-10">
<?php
echo Html::dropDownList('fld_jenis', null, ArrayHelper::map($tStatus, 'id', 'name'), [
'prompt' => Yii::t('app', 'Pilih Jenis...'),
'id' => 'fld_jenis',
'class' => 'dependent-input form-control',
]);
?>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="fld_deskripsi">Rincian :</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="fld_deskripsi" placeholder="Rincian" name="fld_deskripsi" >
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="fld_ket">Keterangan :</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="fld_ket" placeholder="Keterangan" name="fld_ket">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="fld_curr">Currency :</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="fld_curr" placeholder="Mata Uang" name="fld_curr" value="IDR">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="fld_amount">Amount :</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="fld_amount" placeholder="Jumlah" name="fld_amount" value="0">
</div>
</div>
<div class="col-sm-12 form-group">
<?=
Html::submitButton('Simpan', [
'content' => 'Button',
// ‘value’ => Url::to([‘trsmaster/simpan’]),
'value' => 'ok',
'class' => 'btn btn-success',
'id' => 'create-btn',
'name' => 'submitbtn'
])
?>
</div>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>