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
Closed

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

kottenator opened this issue Nov 7, 2017 · 8 comments

Comments

@kottenator
Copy link

@kottenator kottenator 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
Copy link

@ffabiorj ffabiorj commented Nov 26, 2017

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

Loading

@victorouttes
Copy link

@victorouttes victorouttes commented Dec 5, 2017

Same issue here. Django 2.0.

Loading

@ffabiorj
Copy link

@ffabiorj ffabiorj commented Dec 6, 2017

How can we solve this issue?

Loading

@kottenator
Copy link
Author

@kottenator kottenator 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'}))

Loading

@hunterji
Copy link

@hunterji hunterji 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.

Loading

@mateuspadua
Copy link

@mateuspadua mateuspadua commented Dec 28, 2017

I had the same problem with type = hidden

Loading

@v-hunt
Copy link

@v-hunt v-hunt commented Feb 16, 2018

Hi,
Did somebody find any solution?

Loading

camilonova added a commit that referenced this issue Mar 19, 2018
@Alex-Sichkar
Copy link

@Alex-Sichkar Alex-Sichkar commented Apr 11, 2018

I still have this issue (Django 1.11)

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
7 participants