Reputation: 2265
I have this checkboxList:
Html::checkboxList('MyOffices', null, $offices);
It works but the user has to select at least one option. So I would like to add the required attribute to checkboxList
but it doesn't belongs to the model.
Update:
I tried adding this rule to my model file but it didn't work:
[['MyOffices'], 'requiredValue' => 1, 'message' => 'my test message']
Also I tried adding the required attribute in my view file:
Html::checkboxList('MyOffices', null, $offices, ['required' => true]);
Upvotes: 0
Views: 328
Reputation: 1
Try:
Html::checkboxList('MyOffices', null, $offices, ['required' => true]);
Upvotes: 0
Reputation: 131
Try the below code:
['acordul_tc', 'required', 'on' => ['register'], 'requiredValue' => 1, 'message' => 'my test message']
This means that the attribute is required and must be equal to 1, else display error with your message.
Upvotes: 1