Yii Framework Forum: [SOLVED] onKeyEnter pada CHtml::TextField di Yii - Yii Framework Forum

Jump to content

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

[SOLVED] onKeyEnter pada CHtml::TextField di Yii Rate Topic: -----

#1 User is offline   mhdrasad 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 198
  • Joined: 20-April 11
  • Location:Bumi Indonesia

Posted 12 July 2011 - 09:04 PM

Haloooo masta2 Yii.
Minta sample donk , onKeyEnter di Yii

Quote

Misal: saya punya 3 TextField
[TextField_1] // klo disini di tekan enter cursor pindah ke bawah, ke textfield_2
[TextField_2] // klo disini di tekan enter cursor pindah ke bawah, ke textfield_3
[TextField_3] // klo disini di tekan enter cursor pindah ke bawah, focus ke tombol submit.
[submit]


Mohon bombingannya ya gan :D
Wait For True Concept or Finish it With Coding Concept .
#chadnox
0

#2 User is offline   petra 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 218
  • Joined: 20-June 10

Posted 14 July 2011 - 05:16 AM

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'));?>

0

#3 User is offline   mhdrasad 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 198
  • Joined: 20-April 11
  • Location:Bumi Indonesia

Posted 14 July 2011 - 08:38 PM

View Postpetra, on 14 July 2011 - 05:16 AM, said:

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
Wait For True Concept or Finish it With Coding Concept .
#chadnox
0

#4 User is offline   petra 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 218
  • Joined: 20-June 10

Posted 15 July 2011 - 04:52 PM

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
0

#5 User is offline   mhdrasad 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 198
  • Joined: 20-April 11
  • Location:Bumi Indonesia

Posted 17 July 2011 - 08:18 PM

View Postpetra, on 15 July 2011 - 04:52 PM, said:

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
Wait For True Concept or Finish it With Coding Concept .
#chadnox
0

#6 User is offline   petra 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 218
  • Joined: 20-June 10

Posted 17 July 2011 - 10:25 PM

itu enggak harus berurutan..

cuman array isinya from sama to doang kok :)
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