Susan
Susan

Reputation: 97

Symfony: How to disable form fields autocomplete?

I used this in twig :

{{ form_start(form, { 'attr': {'autocomplete': 'off'} })  }}

and this in the controller action :

'attr'=>array('autocomplete' => 'off'

But the autocomplete still not disabled!!!!

Upvotes: 6

Views: 14206

Answers (4)

Quasipickle
Quasipickle

Reputation: 4498

For password fields, use new-password rather that off

Upvotes: 0

long
long

Reputation: 4313

For choiceType field, use:

'choice_attr' => function($choice, $key, $value) {
    return ['autocomplete' => 'off'];
}

Source: https://symfony.com/doc/current/reference/forms/types/choice.html#choice-attr

Upvotes: 1

Arco Voltaico
Arco Voltaico

Reputation: 814

You can use :'attr' => ['autocomplete' => 'disabled']

Upvotes: 7

SpicyTacos23
SpicyTacos23

Reputation: 550

UPDATE: If you are using symfony 4 the proper way is using off

'attr'=>['autocomplete' => 'off']

Upvotes: 11

Related Questions