CJuiDatePicker validations and relation

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:

Thank you, rall0r

Nobody any idea?

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'=>'<='),

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

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…