rall0r
(Rall0r)
February 11, 2011, 4:22pm
1
Hi,
at an search form there are 2 CJuiDatePicker to define the period for an search (to define start- and the enddate).
In order to generate search results, some validating rules are important: "startdate" have to be before or equal "enddate"
In the module I’m using the following rule:
array('STARTDATE','compare','compareAttribute'=>'ENDDATE','operator'=>'<='),
array('ENDDATE','compare','compareAttribute'=>'STARTDATE','operator'=>'>='),
So everythink works fine.
Problems occurs, if one Date-Field is empty, which is "save"/okay for the search-engine but not for yii/model validation. (an empty "STARTDATE" is not lower or equal "ENDDATE")
So how I can define, that empty date-fields are also "valid"?
The following code does not work:
array(‘STARTDATE’,‘boolean’,‘allowEmpty’=>true,‘compare’,‘compareAttribute’=>‘ENDDATE’,‘operator’=>’<=’),
Thank you, rall0r
mdomba
(Maurizio Domba Cerin)
February 14, 2011, 10:54am
3
In your example
array('STARTDATE','boolean','allowEmpty'=>true,'compare','compareAttribute'=>'ENDDATE','operator'=>'<='),
you mix two validators ‘boolean’ and ‘compare’… try only with the compare… it should work… like:
array('STARTDATE','compare','allowEmpty'=>true,'compareAttribute'=>'ENDDATE','operator'=>'<='),
rall0r
(Rall0r)
February 14, 2011, 11:24am
4
Hi mdomba,
thank you for this information.
I tried the following:
array('STARTDATE','compare','allowEmpty'=>true,'compareAttribute'=>'ENDDATE','operator'=>'<='),
array('ENDDATE','compare','allowEmpty'=>true,'compareAttribute'=>'STARTDATE','operator'=>'>='),
If I fill only one field: there is still an validation error.
Something like 'Startdate must be lower or equal like “” ’ (at this example: Enddate was empty)
Thank you
rall0r
mdomba
(Maurizio Domba Cerin)
February 14, 2011, 11:39am
5
allowEmpty… in a rule means that the attribute that will be validated can be empty…
In you case… enddate is empty… and a rule for startdate says… startdate can be empty… if not empty it should be lower or equal to startdate (empty)…
I don’t see a working solution with the built-in validators here… you can use a custom validator to solve this…