Yii2 Activeform afterValidate issue

7.1k views Asked by At

In Yii 1.X version we can use afterValidate inside clientOptions property of CActiveForm class, please let me know the correct way to implement the same in Yii2

1

There are 1 answers

1
iamawebgeek On BEST ANSWER

I just saw these changes. I am very very surprised why core team developers has decided to do so, now the events:

beforeValidate, afterValidate, beforeValidateAttribute, afterValidateAttribute, beforeSubmit, ajaxBeforeSend, ajaxComplete function were moved to front-end side. They are triggered by jQuery trigger function. You can catch the event you need like this:

$("#FORM-ID").on("afterValidate", function (event, messages) {
  // Now you can work with messages by accessing messages variable
  var attributes = $(this).data().attributes; // to get the list of attributes that has been passed in attributes property
  var settings = $(this).data().settings; // to get the settings
});