default value fo CHtml::activeTextArea()


is there a way to set a default value for CHtml::activeTextArea()?

i need that because a have to put a default value in a gii generated textareain form :

$oContentForm = $this->beginWidget('CActiveForm');

echo $oContentForm ->textArea($oModel, 'attributeName', array('rows'=>20,'cols'=>125,'id'=>'ContentID'));


CActiveForm->textArea use by default CHtml::activeTextArea()…

how can i do that ?

..........array('rows'=>20,'cols'=>125,'id'=>'ContentID', 'value'=>'this is the default value')).........


1 thing that bothers me is that when you use the same form as an editing form, i don’t know what will be in the field, could be the default thingy, or could be the model content

anyway, i would do it with js, test it if it is empty and only then put in the default text

like they do with a search field so often on websites

I tryed this but it gives me an empty textarea…

it doeasn’t work because “textarea” tag don’t containt attribute “value”.

an other solution is to use CHtml::textArea(), it contain $value attribute.

textArea() method

i think , as Mukke said, the better way is do it with JS

yes i think both of you are right but i will figure out another possible way to this solution thanks to all

I’m sure this type of questions has been already asked few times on the forum…

To set an initial value you can just assign the desired value to the attribute… like:

$oContentForm = $this->beginWidget('CActiveForm');

$oModel->attributeName="my default value";

echo $oContentForm ->textArea($oModel, 'attributeName', array('rows'=>20,'cols'=>125,'id'=>'ContentID'));


that assignment would be better in the controller (before rendering the view)… so that it’s set only on actionCreate as obviously you don’t want this on actionUpdate

Otherwise it can be auto filled with default value in your db, if I’m correct.

it’s soo good, I need it :D