A
A
Anton2016-05-21 15:55:04
Yii
Anton, 2016-05-21 15:55:04

How to execute validation method with ajax?

Hello,

public function rules() {
     return [
         ['field' ,'method'],
     ];
}

public function method($attribute,$params) {
   $this->addError($attribute,'Error');
}

How to make this method executed by Ajax???

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kim, 2016-07-15
@kimono

You need to create your own MethodValidator:

public function rules() {
     return [
         ['field' , MethodValidator::className()],
     ];
}

And already in the MethodValidator, using the clientValidateAttribute() method, build the validation logic on the client side.
Read more in the docs: #Implementation-of-validation-on-client-side

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question