materialize icon indicating copy to clipboard operation
materialize copied to clipboard

<select> input tag not working in Django

Open erwol opened this issue 9 years ago • 5 comments

Description

<select> tags are not working in Django because they need the class="browser-default" to appear in the browser.

Repro Steps

  1. Create a Form with multiple choices in Django
  2. 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'}),
        
    )

erwol avatar Jun 28 '17 17:06 erwol

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?

DanielRuf avatar Jun 28 '17 17:06 DanielRuf

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

Dogfalo avatar Jun 28 '17 17:06 Dogfalo

Right, should be initalized with material_select() (I thought he did so in his project or component).

http://materializecss.com/forms.html

DanielRuf avatar Jun 28 '17 17:06 DanielRuf

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.

erwol avatar Jun 28 '17 17:06 erwol

as materialize css needs the browser-default set class in select tags

That is new to me. http://materializecss.com/forms.html#select

DanielRuf avatar Jun 28 '17 18:06 DanielRuf