I have a model in which i capture two dates from and to i want to validate on client side so that from < to i wrote a function to validate on server as
public function validateDate($attribute, $params) {
if (!$this->hasErrors()) {
$from = new DateTime($this->from);
$to = new DateTime($this->to);
if (!($from < $to)) {
$this->addError($attribute, 'Dates are not correct');
}
}
}
and add rule to rule array as
[[‘to’], validateDate],
can some one tell how to add client side code for this. I was going through documentation i found this http://www.yiiframework.com/doc-2.0/guide-input-validation.html#implementing-client-side-validation link is it compulsory to create a new validation class and then add write functions there or is there any why to add js code to model class .
I am wondering how to use clientValidateAttribute() (http://www.yiiframework.com/doc-2.0/yii-validators-validator.html#clientValidateAttribute()-detail) in model to generate js code for comparison.
Thanks