Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't override `type="search"` for text field anymore #52

Closed
kottenator opened this issue Nov 7, 2017 · 8 comments

Comments

Projects
None yet
7 participants
@kottenator
Copy link

commented Nov 7, 2017

Hi!

I'm migrating my project from Django 1.9 to 1.11. I have the following code which was working great in Django 1.9 but doesn't work in Django 1.11:

{% render_field form.q type='search' required='required' class='term-input' %}

And here's my Django form:

class SearchForm(forms.Form):
    q = forms.CharField(label='Search')

Only if I explicitly override the field widget's type atribute - it works:

class SearchForm(forms.Form):
    q = forms.CharField(label='Search', widget=TextInput(attrs={'type': 'search'}))

Investigation

AFAIU, Django 1.11 has moved widgets rendering from Python code into templates (which is 100% positive change IMO), but now they treat type attribute in a special way:

{# django-1.11.7/django/forms/templates/django/forms/widgets/input.html #}
<input type="{{ widget.type }}" name="{{ widget.name }}"{% if widget.value != None %} value="{{ widget.value|stringformat:'s' }}"{% endif %}{% include "django/forms/widgets/attrs.html" %} />

So when I override

{% render_field form.q required='required' class='term-input' data-x=1 %}

... - everything works great, but not when I change type :(

@ffabiorj

This comment has been minimized.

Copy link

commented Nov 26, 2017

I have the same issue with type:'password'.

@victorouttes

This comment has been minimized.

Copy link

commented Dec 5, 2017

Same issue here. Django 2.0.

@ffabiorj

This comment has been minimized.

Copy link

commented Dec 6, 2017

How can we solve this issue?

@kottenator

This comment has been minimized.

Copy link
Author

commented Dec 6, 2017

@ffabiorj - somebody could create a pull-request :)

And there's a workaround - specify input type directly in Django form:

class SearchForm(forms.Form):
    q = forms.CharField(label='Search', widget=forms.TextInput(attrs={'type': 'search'}))
@hunterji

This comment has been minimized.

Copy link

commented Dec 13, 2017

I think I'm having the same problem, but with type=hidden. In my case I can't define it in the form because I am disabling some of the fields and need to include a 'hidden' version that holds the original field value so that the form will pass validation. I'm setting the global 'hidden' attribute instead of setting the type.

@mateuspadua

This comment has been minimized.

Copy link

commented Dec 28, 2017

I had the same problem with type = hidden

@v-hunt

This comment has been minimized.

Copy link

commented Feb 16, 2018

Hi,
Did somebody find any solution?

camilonova added a commit that referenced this issue Mar 19, 2018

@ygwain

This comment has been minimized.

Copy link

commented Apr 11, 2018

I still have this issue (Django 1.11)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.