GSTAR
(Omzy83)
December 18, 2009, 3:13pm
1
Here is how I set up activeTextField and activeTextArea, with the aim of having default values upon page load:
<?php echo CHtml::activeTextField($contact, 'name', array('value'=>'Your Name')); ?>
<?php echo CHtml::activeTextArea($contact, 'enquiry', array('value'=>'Details of Enquiry')); ?>
Couple of things:
When there is a validation error, the default value is populated in the field, instead of the posted value
I can’t get the default value for the textarea to display
Can anyone advise how to do this?
notzippy
(Notzippy)
December 18, 2009, 4:08pm
2
By setting the value directly you override the value on the $contact model
Text areas do not have a "value" attribute,
Personally I would set the "default" values on the $contact model class itself, and not supply the html attributes.
nz
GSTAR
(Omzy83)
December 18, 2009, 4:32pm
3
Cheers, thanks for your help.
GSTAR
(Omzy83)
December 18, 2009, 4:42pm
4
How can I check that the posted values are not the default values of the form fields?
In the controler:
in the same way that you put the value?
In the Model:
perhaps creating a variable in the controller and then using it in the model validator
in the controler
public default_value_for_xxxxx='yyyyy';
in the model
public function rules()
{
return array(
array('xxxxx','xxxxxValidator'),
);
}
public function xxxxxValidator()
{
if ($this->default_value_for_xxxxx==$this->xxxxx)
{
.......
}
}
I hope is what you want
bsander
(Sanderb)
December 22, 2009, 8:58am
6
activeTextArea should be able to support pre-filled values, since it’s based on CHtml::tag, which has a $content parameter. You might want to file an issue ticket for that!
GSTAR
(Omzy83)
December 22, 2009, 4:10pm
7
OK in my model I created an attribute:
public $name=‘Your Name’;
Is there a "rule" I can put in the model that will check to see if the submitted value matches $name?
tri
(tri - Tommy Riboe)
December 22, 2009, 5:14pm
8
GSTAR:
OK in my model I created an attribute:
public $name=‘Your Name’;
Is there a "rule" I can put in the model that will check to see if the submitted value matches $name?
Perhaps declare self::YOUR_NAME and use it in a CCompareValidator (compareValue)?
/Tommy
yes tri, Starting from version 1.0.8, CCompareValidator supports different comparison operators. Previously, it only compares to see if two values are equal or not.
http://www.yiiframework.com/doc/api/1.0.11/CCompareValidator#operator-detail
[EDIT]
see http://www.yiiframework.com/doc/cookbook/56/
public function rules()
{
return array(
array('xxxxx','compare','compareValue'=>$this->name,'operator'=>'!='),
);
}
note: $this->name if you put the default value in the controller
self::name if you put the default value in the model
no tested
[EDIT2]
public $name='Your Name';
I think the name "name" is not a good idea, is the same as the model
maybe "name_default_value"
saegeek
(Abdallah)
January 11, 2010, 8:10pm
10
any news about the default activeTextarea value ?
is it available on 1.1rc ?
fouss
(Jsfousseni)
December 23, 2010, 11:48am
11
Are you talking about that? see this link
mdomba
(Maurizio Domba Cerin)
December 23, 2010, 11:57am
12
@fouss
Note that you responded to a question posted on 11 january 2010 from a user that has not been active since 14. jun 2010.
fouss
(Jsfousseni)
December 23, 2010, 3:43pm
13
Thx for let me know that!