Create a way to refresh validators

Sometimes, after model is saved, the rules changes then it makes a bad validation on client side, because javascript is rendered using the old values, currently not exists a easy way to refresh the validators after are created, because yii\base\Model::$_validators is private, then I suggest make yii\base\Model::$_validators protected or implement in yii\base\Model the next function




public function refreshValidators() {

    $this->_validators = $this->createValidators();

}



In Yii 2, the client side validation is enabled by default. But there are many cases you have to turn it off manually (per form or per field) and use the ajax validation instead because of the problem you have described.

Unfortunately this won’t solve the problem, because a change on the server side will not be reflected automatically in the javascript on the client. Also we seldom need to modify the validation code after it was created. Note that the life cycle of the code on the server side is per request.

Try disable the client side validation and use ajax validation instead.