Symfony EntityType Extended with Jquery Validate Plugin

Viewed 17

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?

0 Answers
Related