Disabled or Read Only FORM field pain

hello everyone,

I have a FORM and some dropdown fields in it. How can I disable them or set them ReadOnly?


$options['readonly']=true; // this works only with regular text fields!

works fine with regular text fields, but not with dropdowns, because the $options array there sets the dropdown options, not the actual form field options :( )

thanks,

–iM

Hi,

[font=“Courier New”]<select>[/font] and [font=“Courier New”]<option>[/font] don’t have [font=“Courier New”]readonly[/font] attribute. Only [font=“Courier New”]<input>[/font] and [font=“Courier New”]<textarea>[/font] can have this attribute.

To disable a [font="Courier New"]DropDownList[/font] juste write :


array('disabled'=>'true')

in [font="Courier New"]htmlOptions[/font].

thanks, [bruno_] that did the trick :)

–iM

Hi

i have a problem

i put disable="false" or readonly="false" but the field is always disabled o r readonly

exists any way do it is?

hello Horacio,

just don’t set it at all. It defaults to false anyway.

–iM

hi

mi code is




<div class="simple">

<?php $tipo_documento=Varios::cargarDominio('TIPO_DOCUMENTO'); ?>

<?php echo CHtml::activeLabelEx($model,'tipo_documento'); ?>

<?php echo CHtml::activeDropDownList($model, 'tipo_documento', CHtml::listData($tipo_documento, 'valor', 'descripcion')

,array( 'prompt'=>'Seleccione...','readonly'=>Seguridad::noTieneRolChar('PER_INGRESO'))); ?>

</div><div class="simple">

<?php echo CHtml::activeLabelEx($model,'nro_documento'); ?>

<?php echo CHtml::activeTextField($model,'nro_documento',array('readonly'=>Seguridad::noTieneRolChar('PER_INGRESO'))); ?>

</div>




Seguridad::noTieneRolChar return true or false

use

‘disabled’=>Seguridad::noTieneRolChar(‘PER_INGRESO’)

instead of

‘readonly’=>Seguridad::noTieneRolChar(‘PER_INGRESO’)

[color="#0000FF"]disabled="disabled"[/color]

[color="#FF0000"]disable="false"[/color]

no, not work

is it the solution?




<?php 

    if (Seguridad::tieneRol('PER_INGRESO'))

       echo CHtml::activeDropDownList($model, 'tipo_documento', CHtml::listData($tipo_documento, 'valor', 'descripcion')

          ,array( 'prompt'=>'Seleccione...')); 


    else

       echo CHtml::activeDropDownList($model, 'tipo_documento', CHtml::listData($tipo_documento, 'valor', 'descripcion')

          ,array( 'prompt'=>'Seleccione...','disabled'=>'true'));


?>


</div>

<div class="simple">

<?php echo CHtml::activeLabelEx($model,'nro_documento'); ?>




<?php

   if (Seguridad::tieneRol('PER_INGRESO'))

     echo CHtml::activeTextField($model,'nro_documento');

     else

     echo CHtml::activeTextField($model,'nro_documento',array('readonly'=>'true'));

?>

</div>



did you try this

if this works, why no make

Seguridad::tieneRol(‘PER_INGRESO’) returns a string (‘true’ or ‘false’) instead of a boolean (true or false)?

THE FINAL APROACH




<?php 

   if (!Seguridad::tieneRol('PER_INGRESO')) {

      $readonly=array() ;

      $disabled=array() ;

   }

   else   {

      $readonly=array('readonly'=>'readonly') ;

      $disabled=array('disabled'=>'disabled') ;

   }

   

?>




<div class="simple">

<?php $tipo_documento=Varios::cargarDominio('TIPO_DOCUMENTO'); ?>

<?php echo CHtml::activeLabelEx($model,'tipo_documento'); ?>


<?php 

       echo CHtml::activeDropDownList($model, 'tipo_documento', CHtml::listData($tipo_documento, 'valor', 'descripcion')

          ,array_merge($disabled,array( 'prompt'=>'Seleccione...')));

?>


</div>

<div class="simple">

<?php echo CHtml::activeLabelEx($model,'nro_documento'); ?>




<?php

    echo CHtml::activeTextField($model,'nro_documento',$readonly);

?>

</div>



u can say:

$readonly = array(‘readOnly’=>true);

tieneRol return boolean

noTieneRolChar return char