4

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!!!!

Susan
  • 67
  • 2
  • 9
  • Did you clear the Symfony cache in both environments, dev & prod? – Aaron Belchamber Mar 20 '17 at 19:34
  • 1
    Also, I've seen this issue before, especially with Chrome and was told to set the entire form to autocomplete, that may not be feasible for you, but here's the SO link, I hope this helps. http://stackoverflow.com/questions/32369/disable-browser-save-password-functionality/23927796#23927796 – Aaron Belchamber Mar 20 '17 at 19:37
  • even after clearing the cache it still doesn't work!!! – Susan Mar 20 '17 at 20:12
  • 1
    What you mean by "doesn't work"? Is there no `autocomplete` attribute in field html output? – malcolm Mar 20 '17 at 20:21
  • nooo i want the autocomplete to be OFF but it still work!! – Susan Mar 20 '17 at 20:42
  • 1
    How does the rendered HTML look like? Is there an `autocomplete` attribute with the value `off`? – xabbuh Mar 20 '17 at 21:08
  • this how it looks like in my form : {{ form_start(form, { 'attr': {'autocomplete': 'off'} }) }} – Susan Mar 20 '17 at 21:53
  • Susan, you are not listening to some good suggestions. What is being asked is, when you check the rendered html with your settings, have you checked if `autocomplete` actually gets set at all? You should at least do this test and provide feedback. – Alvin Bunk Mar 21 '17 at 05:12
  • yes autocomplete gets sel att all the fields, that what i meant by "it doesn't work' because i've set it to false in all the fields of the form – Susan Mar 21 '17 at 22:43

3 Answers3

7

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

Gambit
  • 12,256
  • 2
  • 17
  • 18
Arco Voltaico
  • 686
  • 8
  • 22
7

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

'attr'=>['autocomplete' => 'off']
SpicyTacos23
  • 420
  • 3
  • 10
  • I don't think that's a matter of symfony version. The attr will print out exactly what you put there into the html element. If "off" works better then that's likely a matter of html standard that the browser responds properly to. Putting "disabled" will have symfony print that out into the html element instead. If your browser responds to that, you're lucky. Current version of chrome wants "off" like you say =) – Matt Welander Oct 13 '20 at 12:25
0

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

long
  • 3,276
  • 1
  • 16
  • 33