Ad Hoc Validation on checkboxlist

I have an activeForm with model

<?= $form->field($model, ‘name’)->textInput() ?>

<?= $form->field($model, ‘address’)->textInput() ?>

<?= $form->field($dynamicModel, ‘brands’)->checkboxList($brands); ?>

I’m also using ajax validation

Now I want to add validation to the checkboxlist

I found this:

and this:

But I have no idea how to use it

And how to I assign the values to the dynamic model?

It’s from a junctiontable, I know how to get them from the database, but not how to assign them

$dynamicModel = \yii\base\DynamicModel::validateData([‘brands’], [

        [['brands'], 'required'],

        ['brands', 'each', 'rule' =&gt; ['integer']],


i have given you an answer in your stackoverflow post