Reputation: 341
I'm trying to set the html layout of my forms using the helper and layout of crispy form. In other words I have set my form in the following manner.
class MaterialeForm(forms.ModelForm):
data_contabile=forms.DateTimeField(widget=DatePicker(attrs={
class Meta:
model = Materiale
fields = "__all__"
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper()
self.layout = Layout(
Field('conta', id="form-conto", css_class="form-control", name="Conto"))
And after that I have set in my template the html code:
<div class="modal-body">
<label for="conto"></label>
{{form.conto|as_crispy_field}}
but in the layout the id and name does not work properly. In fact if I ispect the page I try the following code:
<select name="conto" class="select form-control form-control" required="" id="id_conto"> <option value="">---------</option> <option value="1" selected="">Materia Prima</option>
</select>
where is the error?
Upvotes: 2
Views: 1794
Reputation: 985
I am also just started using crispy forms. Trying to fix a similar issue, I noticed the layout helper only works when using:
{% crispy form %}
instead of {{ form|crispy}} or any of the template filter variants.
Upvotes: 13