[SOLVED] onKeyEnter pada CHtml::TextField di Yii

Haloooo masta2 Yii.

Minta sample donk , onKeyEnter di Yii

Mohon bombingannya ya gan :D

bukannya tinggal gini aja ya




<?php

Yii::app()->clientScript->registerScript('test', '


$(\'#textfield1\').keypress(function(e){

    if(e.keyCode == 13) {

        $(\'#textfield2\').focus();

    }

});

');

?>


<?php echo CHtml::textField('textfield1', '', array('id' => 'textfield1'));?>


<?php echo CHtml::textField('textfield2', '', array('id' => 'textfield2'));?>



Mabtabz dah om petra…thx bgt om. :D

kalo mau gak kebanyakan if-nya,

tinggal tambahin atribut aja di textfieldnya,




<?php echo CHtml::textField('textfield2', '', array('id' => 'textfield2', 'class' => 'next', 'next' => 'fieldid'));?>



ntar di kodenya ya tinggal




<?php

Yii::app()->clientScript->registerScript('test', '


$(\'.next\').keypress(function(e){

    if(e.keyCode == 13) {

        $('#'.$(this).attr(\'next\')).focus();

    }

});

');

?>


<?php echo CHtml::textField('textfield1', '', array('id' => 'textfield1', 'class' => 'next', 'next' => 'textfield2'));?>

<?php echo CHtml::textField('textfield2', '', array('id' => 'textfield2', 'class' => 'next', 'next' => 'textfield3'));?>

<?php echo CHtml::textField('textfield2', '', array('id' => 'textfield3', 'class' => 'next', 'next' => 'textfield4'));?>

<?php echo CHtml::textField('textfield2', '', array('id' => 'textfield4', 'class' => 'next', 'next' => 'submit'));?>



kode di atas belum dicoba…

kalo gak mau nambahin attribut ‘next’ ya tinggal taro array javascript buat ngemap

array(‘from’ => ‘to’, ‘from’ => ‘to’, dst);

ato juga bisa kalo mau pake .parent() atau .sibling(),

banyak jalannya :P

Wow kereennn!!!.

Blm saya coba sih, tapi klo di liat2 itu berurutan ya?. Mending pake if aja deh, kan bisa kita tentuin mau focus ke mana setelah enter :D

itu enggak harus berurutan…

cuman array isinya from sama to doang kok :)