<select> input tag not working in Django
Description
<select> tags are not working in Django because they need the class="browser-default" to appear in the browser.
Repro Steps
- Create a Form with multiple choices in Django
- Try to render it; you won't be able to see it
The solution is to overwrite the forms widget, but I think this should be fixed from materialize css project.
class JustAnotherForm(forms.ModelForm):
multiplechoicefield= forms.CharField(
max_length=124,
widget=forms.Select(
choices=ARTWORK_TYPES,
attrs={'class': 'browser-default'}),
)
Can you provide a codepen which reproduces it? Did you already inspect the element in the developer tools of the browser to find the problematic code?
The select is meant to be initialized which you are not doing. In any case, we likely will make some changes to default elements in the upcoming releases
Right, should be initalized with material_select() (I thought he did so in his project or component).
http://materializecss.com/forms.html
Hey @DanielRuf, I already found the problem when I post the issue. Sorry if it's not well explained. The thing is that Django renders select tags without any classes attached to the element, and as materialize css needs the browser-default set class in select tags, Django will render the template but you won't be able to see the select. The Django-side fix is to initialize the component as I posted up here. Maybe an easy fix'd be to allow native select tags. Thank you @Dogfalo.
as materialize css needs the browser-default set class in select tags
That is new to me. http://materializecss.com/forms.html#select