I am seeking to control browser behavior. How do I add autocomplete="off" attribute to the title text field of a content type? Is there a contrib module?

I noticed this one for Drupal: https://www.drupal.org/project/no_autocomplete. However, I want to have this control over any text field, especially the title field, of any content type.

This is a pretty basic thing to do when building pages in html and adding the attribute to the input tag. How are you doing it on Backdrop? Are you doing it with jQuery by adding a javascript file to the *.info file in the theme?

Accepted answer

Hi stefano,

...How are you doing it on Backdrop?

In Backdrop we have hooks for that. In your case it would be hook_form_BASE_FORM_ID_alter().

In your theme's template.php add:

function YOURTHEME_form_node_form_alter(&$form, &$form_state, $form_id) {
  $form['title']['#attributes']['autocomplete'] = 'off';
}

Where "YOURTHEME" should be your theme's name.

That should do the trick.

Comments

indigoxela's picture

Hi stefano,

...How are you doing it on Backdrop?

In Backdrop we have hooks for that. In your case it would be hook_form_BASE_FORM_ID_alter().

In your theme's template.php add:

function YOURTHEME_form_node_form_alter(&$form, &$form_state, $form_id) {
  $form['title']['#attributes']['autocomplete'] = 'off';
}

Where "YOURTHEME" should be your theme's name.

That should do the trick.

I popped it into the seven theme. Thanks.

indigoxela's picture

I popped it into the seven theme.

Oops, that's a bad idea! You shouldn't hack core. The next core update will overwrite that again. Create a subtheme instead - that's the proper way to do this.

Do you need help with creating a subtheme? It's not difficult, promised.

I appreciate the follow up. I noticed the subtheme method earlier and will use that later today. However, I did hack the core version of the seven theme on this one just to see that it worked. Thanks for the reminder.