Yii Framework Forum: CStringValidator allowEmpty=>false - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CStringValidator allowEmpty=>false Rate Topic: -----

#1 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 13 February 2010 - 04:05 AM

I've just noticed that if I use CStringValidator with allowEmpty => false and an attribute's value is an empty string, then the validator doesn't show any error. In a combination with CRequiredValidator it works well and shows "Attribute can't be blank" message:

array('name', 'required'),
array('name', 'length', 'max'=>100, 'allowEmpty'=>false),


I just wonder if it is an expected behavior or I'm missing something :huh:
0

#2 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 13 February 2010 - 04:23 AM

View Postandy_s, on 13 February 2010 - 04:05 AM, said:

I've just noticed that if I use CStringValidator with allowEmpty => false and an attribute's value is an empty string, then the validator doesn't show any error. In a combination with CRequiredValidator it works well and shows "Attribute can't be blank" message:

array('name', 'required'),
array('name', 'length', 'max'=>100, 'allowEmpty'=>false),


I just wonder if it is an expected behavior or I'm missing something :huh:


Should not make a difference whether what's not required is empty or not :rolleyes:

/Tommy
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
0

#3 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 13 February 2010 - 05:07 AM

View Posttri, on 13 February 2010 - 04:23 AM, said:

Should not make a difference whether what's not required is empty or not :rolleyes:

/Tommy


You are right, but it doesn't look intuitive to me when I disallow a field to be empty, but it can be empty anyway :) Had to spend some time to figure this out...
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users