Add validator for dynamically added field to yii\base\model object

Hello, I’m working on a behavior that will add dynamic fields including validation to its owner. Adding a field’s validator (here just a required validator) in attach-method works well on a yii\db\ActiveRecord object but it won’t validate the input of a yii\base\Model object on server side (though it does on client side). This is my attach method:

    public function attach($owner)
    {
        parent::attach($owner);
        $fields = $this->getFields();
        $validators = $this->owner->getValidators();
        foreach ($fields as $attribute) {
           $validators->append(Validator::createValidator('required', $this->owner, $attribute->field));
        }
    }

For a yii\base\Model object I put the same code in beforeValidate method and - hooray - it worked. But I feel this is not very elegant. Any ideas how this can be done better?