colt
(Linija)
May 18, 2010, 2:36pm
1
Hello,
I’m using default Gii Crud and validation to Begin End date attributes like this:
public function rules()
{
return array(
array('SEnd','compare','compareAttribute'=>'SBeg','operator'=>'>', 'allowEmpty'=>false , 'message'=>'wrong', 'on'=>'create, update'),
array('SName, SBeg, SEnd', 'required'),
array('SName', 'length', 'max'=>50),
array('SComm', 'safe'),
array('SeaID, SName, SBeg, SEnd, SComm', 'safe', 'on'=>'search'),
);
}
Now I noticed that validation is somehow skipped - only rarely it is done and I don’t know the reason why, have you got such a problems? Where could be the reason for skipping compare validation.
[edit]
BTW How to add simple TRIM to entered create form field? I see other frameworks has a build in TRIM function.
Greetings,
CoLT
tri
(tri - Tommy Riboe)
May 18, 2010, 3:17pm
2
CoLT:
Hello,
I’m using default Gii Crud and validation to Begin End date attributes like this:
public function rules()
{
return array(
array('SEnd','compare','compareAttribute'=>'SBeg','operator'=>'>', 'allowEmpty'=>false , 'message'=>'wrong', 'on'=>'create, update'),
array('SName, SBeg, SEnd', 'required'),
array('SName', 'length', 'max'=>50),
array('SComm', 'safe'),
array('SeaID, SName, SBeg, SEnd, SComm', 'safe', 'on'=>'search'),
);
}
Now I noticed that validation is somehow skipped - only rarely it is done and I don’t know the reason why, have you got such a problems? Where could be the reason for skipping compare validation.
[edit]
BTW How to add simple TRIM to entered create form field? I see other frameworks has a build in TRIM function.
Greetings,
CoLT
I guess it will be locale dependent and may possibly be dependent on the number of characters entered. The standard CCompareValidator just use the inherent operators (==, !=, >, >=, <, <=) on the two operands.
A different approach might be to convert to unix dates in beforeValidate.
Edit:
And of course the most obvious solution is a customized compareDateValidator.
/Tommy
colt
(Linija)
May 22, 2010, 9:40pm
3
tri:
I guess it will be locale dependent and may possibly be dependent on the number of characters entered. The standard CCompareValidator just use the inherent operators (==, !=, >, >=, <, <=) on the two operands.
A different approach might be to convert to unix dates in beforeValidate.
Edit:
And of course the most obvious solution is a customized compareDateValidator.
/Tommy
Could You give an example of your possible conversation to Unix date?
Yet another problem:
How to specify TRIM function in Yii style, e.g. entering Name without blank spaces in left/right side (e.g. LTRIM and so on)
Thanks for help in advance!
CoLT
tri
(tri - Tommy Riboe)
May 23, 2010, 11:29am
4
CoLT:
Could You give an example of your possible conversation to Unix date?
Yet another problem:
How to specify TRIM function in Yii style, e.g. entering Name without blank spaces in left/right side (e.g. LTRIM and so on)
Thanks for help in advance!
CoLT
PHP strtotime() seems to do the job. I’m still working on this so I might reconsider. No need for different locales in my case.
protected function beforeValidate()
{
...
if (!($this->date_in_db = strtotime($this->date_from_view)))
$this->addError('date_...', 'Bad date');
}
Leave the property for the view in a format suitable for redisplay, in case the validation fails.
There’s a filter validator that can be used with trim().
See the first example here:
http://www.yiiframework.com/doc/api/CFilterValidator
/Tommy
colt
(Linija)
May 23, 2010, 1:59pm
5
tri:
PHP strtotime() seems to do the job. I’m still working on this so I might reconsider. No need for different locales in my case.
protected function beforeValidate()
{
...
if (!($this->date_in_db = strtotime($this->date_from_view)))
$this->addError('date_...', 'Bad date');
}
Leave the property for the view in a format suitable for redisplay, in case the validation fails.
There’s a filter validator that can be used with trim().
See the first example here:
http://www.yiiframework.com/doc/api/CFilterValidator
/Tommy
Thanks! Solved trimming with Filter:
public function rules()
{
return array(
...
array('OName', 'filter', 'filter'=>array($this,'trimmer')),
...
);
}
And custom function:
function trimmer($value)
{
$newValue = trim($value);
return $newValue;
}
And about the validation problems, I just removed ‘on’=> params and it works fine now
Thanks again, if anyone has something to add you’re welcome!
CoLT