ActiveForm Integer Validation - Comparison Error

Hello all,

This feels like something that will have been solved some time ago but here goes.

I have an ActiveForm with min_capacity and max_capacity fields and the following issues:

[list=1]

[*]They only validate on change of their value, rather on the change of either value.

[*]They validate against the first digit of each integer. eg: 2 > 11 because 2 > 1.

[*]The only proceed to validate against following digits if the first digits are equal.

[/list]

In the Model:




public functioon rules()

{

return [

[['min_capacity', 'max_capacity'], 'integer'],

[['min_capacity'],'compare','compareAttribute'=>'max_capacity','operator'=>'<=',],

[['max_capacity'],'compare','compareAttribute'=>'min_capacity','operator'=>'>=',]

];

}



On the form:




<div class="col-xs-10 col-sm-6 col-md-2">

  <?php $model->min_capacity = 0 ?>

  <?= $form->field($model, 'min_capacity')->dropDownList(array_combine(range(0, 100), range(0, 100))) ?>

</div>

<div class="col-xs-10 col-sm-6 col-md-2">

  <?php $model->max_capacity = 20 ?>

  <?= $form->field($model, 'max_capacity')->dropDownList(array_combine(range(0, 100), range(0, 100))) ?>

</div>



Can anybody point me towards a solution or a workaround?

Much appreciated!

Cheers,

Adrian

Values are compared as strings by default: yii\validators\CompareValidator::$type.




public functioon rules()

{

return [

[['min_capacity', 'max_capacity'], 'integer'],

[['min_capacity'],'compare','compareAttribute'=>'max_capacity','operator'=>'<=', 'type' => 'number'],

];

}

Marvelous!

Thank you.

Also; facepalm at ‘functioon’ in the above code - that was me typing it out by hand.

Cheers,

Adrian