Symfony 4 – Can not customize attr for form field in formBuilder

I have a feature that allows me to round the corners of my buttons with this code:

<input type="checkbox" class="custom-control-input" id="toggle-border-radius">
<label class="custom-control-label" for="toggle-border-radius">Border radius</label>

which will call this JS script :

// toggle border radius
    $("#toggle-border-radius").change(function (e) {

But this is manually written code and I would like to use a real form and keep the same functionality. So I created my form with the formBuilder like this:

//... other fields
->add('activeBorderRadius', CheckboxType::class, [
                'required' => false,
                'label' => "Bords arrondis",
                'label_attr' => [
                    'class' => 'custom-control-label',
                    'for' => 'toggle-border-radius'
                'attr' => [
                    'class' => 'custom-control-input',
                    'id' => 'toggle-border-radius'

But when I load the page, the JS script doesn’t work. And when I inspect the source code, I find this :

<input type="checkbox" id="parametres_sidebarOptions_activeBorderRadius" name="parametres[sidebarOptions][activeBorderRadius]" class="custom-control-input form-check-input" value="1">

<label class="custom-control-label form-check-label" for="parametres_sidebarOptions_activeBorderRadius">Bords arrondis</label>

Why can’t I have the attributes that I choosen ?

Thanks for your help

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *