开发者

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 :)


  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'}))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜