Hi,
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'));
$this->endWidget();
CActiveForm->textArea use by default CHtml::activeTextArea()…
how can i do that ?
binkabir
(Binkabir)
February 25, 2011, 10:09am
2
Hi,
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'));
$this->endWidget();
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')).........
;
Mukke
(Ruben Decleyn)
February 25, 2011, 10:13am
3
binkabir:
..........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
binkabir:
..........array('rows'=>20,'cols'=>125,'id'=>'ContentID', 'value'=>'this is the default value')).........
;
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
binkabir
(Binkabir)
February 25, 2011, 10:50am
5
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
mdomba
(Maurizio Domba Cerin)
February 25, 2011, 11:07am
6
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'));
$this->endWidget();
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
teher811
(Thomas Roch)
February 25, 2011, 1:53pm
7
Otherwise it can be auto filled with default value in your db, if I’m correct.