Hi,
I have a form and a formset on the same page. I want to use crispy forms layout function. However: when I use the {{form | crispy}}
it works fine. When I use the {% crispy form %}
I can’t submit the form and the submit button does nothing. Does anyone know why?
The form section in my template:
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ formset.management_form }}
{% crispy blog_form %}
<div class="formset corner mt-5" id='formset'>
<div class='text-center'>
<h2>Add image gallery</h2>
</div>
{% for form in formset %}
{% for hidden in form.hidden_fields %}
{{ hidden }}
{% endfor %}
<div class='image-form'>
{% crispy form %}
</div>
{% endfor %}
<button id='add-form' class='my-5 btn btn-secondary text-center' type="button">Add</button>
</div>
<div class='text-center mt-5'>
<button class='my-5 btn btn-secondary' type="submit">Save</button>
</div>
</form>
and my two forms:
class BlogForm(forms.ModelForm):
class Meta:
model = Blog
fields = ['name','teaser','hero_image','text','video','category_tag','brand_tag','bottle_tag', 'type_tag']
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_tag = False
self.helper.render_hidden_fields = True
self.helper.layout = Layout(
Div(
Row('name', css_class='form-row my-1'),
Row('teaser', css_class='form-control, my-1'),
Row('text', css_class='form-control, my-1'),
Row('hero_image', css_class='form-control-file form-row my-1'),
Row('video', css_class='form-control-file form-row my-1'),
Row('footer_image', css_class='form-control-file form-row my-1'),
),
Div(
HTML("""<h3 class='text-center'>Max 4 tags</h3>"""),
Row(
Column('category_tag', css_class='form-group col-md-3 my-1'),
Column('brand_tag', css_class='form-group col-md-3 my-1'),
Column('bottle_tag', css_class='form-group col-md-3 my-1'),
Column('type_tag', css_class='form-group col-md-3 my-1'),
css_class='form-row my-1'
),css_class='corner px-3 py-2'),)
class BlogImageForm(forms.ModelForm):
class Meta:
model = BlogImage
fields = ['image', 'image_text']
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_tag = False
self.helper.render_hidden_fields = True
self.helper.layout = Layout(
Div(
Row('image', css_class='form-control-file form-row my-1'),
Row('image_text', css_class='form-control, my-1'),
))