php - Ad Hoc Validation on checkboxlist yii2 -
i have activeform model
<?= $form->field($model, 'name')->textinput() ?> <?= $form->field($model, 'address')->textinput() ?> <?= $form->field($dynamicmodel, 'brands')->checkboxlist($brands); ?> ...
i'm using ajax validation
want add validation checkboxlist
i found this: http://www.yiiframew...-hoc-validation
, this: http://www.yiiframew...hvalidator.html
but have no idea how use
and how assign values dynamic model?
it's junctiontable, know how them database, not how assign them
$dynamicmodel = \yii\base\dynamicmodel::validatedata(['brands'], [ [['brands'], 'required'], ['brands', 'each', 'rule' => ['integer']], ]);
i guess you:
// controller code: $dynamicmodel = new dynamicmodel(); $dynamicmodel->defineattribute('brands', $value = null); $dynamicmodel->addrule(['brands'], 'required']); $dynamicmodel->addrule(['brands', 'each', ['rule' => ['integer']]]); // load submitted post data $dynamicmodel->load(yii::$app->request->post()); // validation $dynamicmodel->validate(); // view code <?= $form->field($dynamicmodel, 'brands')->checkboxlist(['1'=>'brand 1', '2'=>'brand 2']) ?>
Comments
Post a Comment