0

I have a one table, the name table is 'siswa', and has primary Key 'nim' and other field 'nama','alamat','tanggal_lahir' and other. I want to fill all fieldtext base dropdownlist in Yii framework. with my code is shown/updated with one textfield only, I want populate all textfield.

Here my view form_ code :

<?php
Yii::app()->clientScript->registerScript("combo-change", "
    $(document).ready(function(){
        $('#nim').change(function(){
        sel = $(this);
        console.log(sel.val());
            if(sel.val() != '' ){
                $('#Siswa_nama').val(sel.val());
                $('#Siswa_nama').attr('disabled', 'disabled');

                $('#Siswa_alamat').val(sel.val());
                $('#Siswa_alamat').attr('disabled', 'disabled');
                                }
        });
    });
");
?>

<?php $SiswaArray = CHtml::listData(Siswa::model()->findAll(array(
    //'order'=>'nama ASC',
    //'group' => 'kelas',
    //'distinct' => true
)),'nama','nim');
?>

<?php echo $form->dropDownList($model, 'nim', $SiswaArray,   array('class'=>'span3', 'empty' => '-- select NIM --', 'id' => 'nim')); ?>

<div class="row">
    <?php echo $form->labelEx($model,'nama');?>
    <?php echo $form->textField($model,'nama', array('class'=>'span2', 'id' => 'Siswa_nama', 'placeholder'=>'nama')); ?>
       </div>
<div class="row">
<?php echo $form->labelEx($model,'Alamat');?>
<?php echo $form->textField($model,'alamat', array('class'=>'span3',   'id' => 'Siswa_alamat', 'placeholder'=>'alamat')); ?>

</div>

Even, the output only 'nama' is updated, but alamat or other not updated. like here : enter image description here

I hope there a answer or solution for this, I confused, spend a week for this. Hope Your Answer.

Thank you,

Bcktr
  • 208
  • 1
  • 8
  • 22
  • As I see in your output image, both Nama and Alamat has been disabled and changed. Can you explain exactly what is your problem? Can you provide more information? I think your problem is related to jquery , not Yii. But I don't see any problem in your code. If I understand your problem correctly, I will post you an answer. – hamed Mar 06 '15 at 04:24
  • @hamed Thank you for your answer, Ok, you are right Nama and Alamat has been changed, but Alamat is changed same as value field 'NAMA' on the table. The table is has NIM, NAMA and Alamat Field. So for output above image, NIM from dropdown 12345, then 'NAMA' is "backtrack", the Alamat should be an street address, such as "bla bla bla.St" – Bcktr Mar 06 '15 at 07:46
  • Ok, I will post you my answer. – hamed Mar 06 '15 at 08:29

1 Answers1

0

in your controller: SiswaController.php

function actionCreate(){ //if it is create action
   //add this code if you have $model= new Siswa;
   $model->alamat = $model->alamat;

}
Liza
  • 808
  • 2
  • 13
  • 30
  • Thanks for your answer, but it still same result. From my feel The problem is from "$SiswaArray=CHtml::listData(Siswa::model()->findAll(array()),'nama','nim')" Look, this is select only field 'nim' for dropdown and 'nama' for first textfield. So how to findAll by all field table? – Bcktr Mar 06 '15 at 03:52
  • `findAll(),'nama','nim'); echo $form->dropDownList($model,'nim',$SiswaArray ,array('empty'=>'Select Here')); ?>` can you elaborate your question? im sorry but i dont understand it clearly. thanks – Liza Mar 06 '15 at 05:25
  • I mean, the 'alamat' value is not updated because that code maybe only store 'nama' and 'nim' only (nim for populate dropdown, and nama for first textfield, so the last textfield is same value. caused thats code only store field 'nim' and 'name'. What about you, Is true? – Bcktr Mar 06 '15 at 06:27