Compare two numbers with compare validator doesn't work

Hi guys,

I’m trying to validate two numbers with the core compare validator, but it doesn’t work.

Here are my rules:




[['startYear', 'endYear'], 'integer', 'min' => 1900, 'max' => $this->maxYear],

['startYear', 'compare', 'compareValue' => 'endYear', 'operator' => '<='],



Both field are associated with input of type number.

On the client side as soon as I enter a value in startYear, the error message appears and it won’t dissapear even if I set endYear to a value greater than startYear.

If I disable javascript to test the server side validation, it’s doing nothing.

Do I have something wrong with my rules? I know I could do custom validator but I’d prefer using the core one.

Thanks,

Alex

You should use ‘compareAttribute’ in the second validator instead of compareValue. compareValue needs a constant value, which means your validator is trying to match startYear to the string “endYear”.

Right on! Thanks!

I think it was too late yesterday. I never noticed the ‘compareAttribute’ in the doc.