Yii Framework Forum: [Ask] Mengisi Text Field Otomatis Berdasarkan Dropdownlist Yang Dipilih - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[Ask] Mengisi Text Field Otomatis Berdasarkan Dropdownlist Yang Dipilih Rate Topic: -----

#1 User is offline   NewMember 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 20-June 14

Posted 11 July 2014 - 10:29 PM

Pagi Yii-ers

Saya ingin bertanya, bagaimana membuat textfieldnya terisi berdasarkan dropdownlist yang dipilih, dropdownlist bersifat dinamis.

Berikut gambarnya,,
Attached File  list.PNG (11.86K)
Number of downloads: 19

untuk baris yang pertama textfield berhasil diisi otomatis,
tetapi pada item berikutnya tidak.

berikut code yang saya gunakan :

- AutoCompleteController
    public function actionCreate() {
        if (Yii::app()->request->isAjaxRequest && $_POST['serah']['id_barang_pakai']) {
            for ($x = 0; $x < count($_POST['serah']['id_barang_pakai']); $x++) {
                $modelBarang = barang::model()->findByPk($_POST['serah']['id_barang_pakai'][$x]);
                echo CJSON::encode($modelBarang);
            }
        } else {
            $model = new serah();
            $this->render('create', array(
                'model' => $model,
            ));
        }
    }


- view
 <br><b>List Aset :</b>
        </thead>
        <tbody>
            <tr>
                <td>
                    <?php
                    echo $form->dropDownList($model, 'id_barang_pakai[]', CHtml::listData(barang::model()->findAllByAttributes(array('status' => 'Tersedia')), 'id_barang', 'nama_barang'), array('empty' => '- Pilih Aset -',
                        'ajax' => array(
                            'type' => 'POST',
                            'url' => CController::createUrl('/AutoComplete/create'),
                            'beforeSend' => 'function(data){if($(this+ ":selected").val()==""){alert("Silakan Pilih");return false;}}',
                            'dataType' => 'json',
                            'success' => 'function(data){$("#serah_kondisi").val(data.kondisi);$("#serah_status").val(data.status);}',
                        ),
                      )
                    );
                    ?>
                </td>
                <td>
                    <?php echo $form->textField($model, 'kondisi[]', array('class' => 'kondisi'), array('size' => 60, 'maxlength' => 80)); ?>
                </td>
                <td>
                    <?php echo $form->textField($model, 'status[]', array('class' => 'status'), CHtml::listData(barang::model()->findAll(array('order' => 'id_barang')), 'id_barang', 'status')); ?>
                </td>   
                <td><input type="button" name="delRow" value="Delete Item" class="delRow" /></td>


Mohon bantuannya, terima kasih
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users