hi there
i have a required field that will get its value from multiple dropdowns and at least one of them must be selected.
the problem is the validation only works for first dropdown
model:
class Ads extends ActiveRecord {
....
....
public $sub_categories;
public function rules() {
$rules = [
['sub_categories', 'required'],
......
......
];
return $rules;
}
view:
.........
.......
<table style="table-layout: fixed;">
<?php
$categories = Category::find()->all();
for($index = -1; $index < count($categories) - 1; ):?>
<tr>
<?php $index++; if(isset($categories[$index])): ?>
<td><?php echo $form->field($model, 'sub_categories')->dropDownList(ArrayHelper::map($categories[$index]->subCategories, 'id', 'title'), ['prompt' => $categories[$index]->name]);?></td>
<?php endif; ?>
<?php $index++; if(isset($categories[$index])): ?>
<td><?php echo $form->field($model, 'sub_categories')->dropDownList(ArrayHelper::map($categories[$index]->subCategories, 'id', 'title'), ['prompt' => $categories[$index]->name]);?></td>
<?php endif; ?>
<?php $index++; if(isset($categories[$index])): ?>
<td><?php echo $form->field($model, 'sub_categories')->dropDownList(ArrayHelper::map($categories[$index]->subCategories, 'id', 'title'), ['prompt' => $categories[$index]->name]);?></td>
<?php endif; ?>
</tr>
<?php endfor; ?>
</table>
......
.......
how to set validation rules?
thanks in advanced