给出一种类型,它会生成这种HTML:
<div class="form-check">
<input
type="checkbox"
id="app_user_responsibilities_14"
name="app_user[responsibilities][]"
data-responsibility-description="A description."
class="form-check-input"
value="14">
<label class="form-check-label" for="app_user_responsibilities_14">Checkbox label</label>
</div>
如何使用Symfony DOM搜寻器专门对其打勾?
我尝试过:
$form->setValues([
'app_user[username]' => $username,
'app_user[responsibilities]' => [
14
],
]);
14
是输入的Responsibility
ID和value
。
但是运行测试时出现错误:
1) Tests\App\Controller\UserControllerTest::testCreateUserWithResponsibility14
InvalidArgumentException: Input "app_user[responsibilities][]" cannot take "14" as a value (possible values: 8).
答案 0 :(得分:0)
由于索引不同于该值,因此需要在选项中使用disableValidation函数:
$form->disableValidation()
->setValues([
'app_user[username]' => $username,
'app_user[responsibilities]' => [
14,
],
]);