eronn
eronn

Reputation: 1830

Symfony - FormType - set field display:none by default

in my formType on Symfony I try to hide a default field.

So I did like this:

        ->add('amountReduction', NumberType::class, [
            "required" => false,
            "label" => "Montant de la réduction",
            "attr" => [
                "style" => "width: 200px; display: none;"
            ],
        ])

The problem is that the label is still visible. I would like to display: none; the whole field by default.

The goal is then that in the template, I can make a $(".field").show() which will display the label and the entire field

Thanks for your help

Upvotes: 0

Views: 1376

Answers (1)

Frank B
Frank B

Reputation: 3697

Use the row_attr option.

->add('amountReduction', NumberType::class, [
            "required" => false,
            "label" => "Montant de la réduction",
            "row_attr" => [
                "class" => "d-none"
            ],
        ])

Upvotes: 2

Related Questions