Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is attr 'gtbfieldid' and how to avoid autocomplete behavior?

I have this simple form:

class PagoDesde(forms.Form):
    from django import forms as f
    desde = f.DateField(input_formats=['%d/%m/%Y'])

In my template:

    {{ form.desde }}

And has associated a jqueryui.datepicker in the document.ready

    $("#id_desde").datepicker();

The html result is:

<input type="text" id="id_desde" name="desde" 
class="hasDatepicker" gtbfieldid="598"/>

And it works great, but I have

2 questions:

  • what is gtbfieldid="598"? does jquery add that?
  • how to avoid the autocomplete behavior of the browsers in this textfield?

thanks :)

like image 285
panchicore Avatar asked Nov 15 '09 20:11

panchicore


1 Answers

  1. The gtbfieldid attribute is added dynamically by the Google Toolbar to the <input> and <select> tags that it thinks it can fill in for you.

  2. If you add the autocomplete="off" attribute to the <form> tag that contains them, then the Google Toolbar will not add these gtbfielid attributes, and its autofill functionality will not be available when filling out that form.

Both of these attributes are non-standard XHTML, so your form will fail validation but if this autofill behavior is causing problems for your visitors, then adding the autocomplete="off" attribute is the only workaround to stop the Google Toolbar from manipulating your form elements and offering to try to fill it in for the user.

Here's how you'd set the autocomplete attribute (in django):

class PagoDesde(forms.Form):
    from django import forms as f
    desde = f.DateField(input_formats=['%d/%m/%Y'],
                        widget=forms.TextInput(attrs={'autocomplete': 'off'}))
like image 136
SmileyChris Avatar answered Sep 30 '22 05:09

SmileyChris