7

I am new in YII, i am wondering if the text-field in YII can made non-editable. If so can anyone answer. I do the following way..

<?php echo $form->labelEx($model,'first_name'); ?>
    <?php echo $form->textField($model,'first_name',array('setEnabled' => false)); ?>

This is not working.

tnchalise
  • 1,573
  • 2
  • 18
  • 38

1 Answers1

13

Use readonly instead:

<?php echo $form->textField($model,'first_name',array('readonly' => true)); ?>

For no blinking, go for disabled attribute:

<?php echo $form->textField($model,'first_name',array('disabled' => true)); ?>

Both behave differently so be sure to check that out.

bool.dev
  • 17,508
  • 5
  • 69
  • 93
  • Works.. But the editable cruser blinks over the text-filed. Any idea to remove that also? – tnchalise Dec 21 '12 at 05:54
  • 1
    that is browser dependent, lemme see if i can find anything, no blinking in chrome(can't even select field), in firefox, can select, but no blinking, which browser are you testing in? – bool.dev Dec 21 '12 at 06:01
  • 1
    Exactly, the issue is browser dependency. Initially i tested in **firefox**. Now i realized. Thanks. – tnchalise Dec 21 '12 at 06:09
  • 1
    i made an edit, check it out, you wanted disabled in the beginning, so used it, just that you had tried with wrong code. For all htmlOptions, remember that html attributes are named exactly the same, as in if html attribute `disabled` exists, it'll be the same for htmlOptions also – bool.dev Dec 21 '12 at 06:14