I encounter a problem related to the use of the EntityType with the extended and multiple set to true (which generates checkboxes) and then validating each field separately (required or not) using the JqueryValidate plugin.
I'm using the automatic rules set by the class and attributes, so all fields work well but the checkboxes.
This happens because the validator uses the attribute name to set validation rules, but each validation rule is only applied once per name, so only the first checkbox is validated. This combined with the impossibility to change the names for the choices of an EntityType with extended and multiple, makes it impossible to use this configurations together.
CODE
FormType
$builder
->add('checkboxes', EntityType::class, [
'class' => MyClass::class,
'required' => false,
'expanded' => true,
'multiple' => true,
]);
Checkboxes rendered
<input type="checkbox" id="appbundle_myclass_checkboxes_1" name="appbundle_myclass[checkboxes][]" value="1">
<input type="checkbox" id="appbundle_myclass_checkboxes_2" name="appbundle_myclass[checkboxes][]" value="2" required="">
QUESTION
Is there a way to change the name attribute of those checkboxes so I can do multiple validations on them?
Or is there a workaround to make the validator work in these cases?
requiredand out of the group sharing the samename, at least one from the group is required to be checked. If you have some that need to be checked and others that do not, then they should not all be in the same group with the samename.name? That makes no sense as that's not how checkboxes are supposed to work. Only checkboxes in a grouping share the samename, such as "yes", "no", "maybe" to answer one question, and then another question might also have "yes", "no", "maybe" but this group shares a differentname. Otherwise the form's post array will be nonsense and you won't know which answers are for which questions.