Search code examples
django-crispy-forms

Crispy form layout hide files


crispy_forms    Crispy_Forms    1.14.0
crispy_forms_foundation Crispy_Forms_Foundation 0.8.0
Django      3.2.11

I'm trying to migrate from django 2 to django 3, but stuck with empty forms.

class Myform(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.layout = Layout(
             Fieldset( 'This is shown:'  ),
             Column('myfield', css_class='large-4'),  #hidden
             Column('myfield2', css_class='large-4'), #hidden
)

Input fields are not rendered in template (you can see only the Fieldset header text 'This is shown:').

I've discovered that deleting the self.helper.layout = Layout() in the init method, make the fields rendered correctly in the template.

Any idea on how to fix this?


Solution

  • It seems that Column doesn't exist anymore, replace with:

    Field('myfield', css_class="black-fields")