Lucas Veiga
Lucas Veiga

Reputation: 197

crispy-form's Helper doesn't take effect

It seems the FormHelper simply doesn't anything. Here's my Form:

class PerguntarForm(forms.Form):
    title = forms.CharField(label='Título', max_length=200)
    categoria = forms.ModelChoiceField(queryset=Category.objects.all(), empty_label=None)
    orcamento = forms.FloatField(label='Preço máximo')

    def __init__(self, *args, **kwargs):
        super(PerguntarForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper(self)
        self.helper.layout.append(Submit('save', 'save'))
        self.helper.layout = Layout(
            PrependedText('orcamento', ',00', active=True),
        )

However, PrependedText isn't applied to the 'orcamento' field when rendered. The layout append doesn't either, which I placed just to see if something happened.

Here's the output:

<div id="div_id_title" class="form-group"><label for="id_title" class="control-label  requiredField">
                Título<span class="asteriskField">*</span></label><div class="controls "><input class="textinput textInput form-control" id="id_title" maxlength="200" name="title" type="text" /> </div></div><div id="div_id_categoria" class="form-group"><label for="id_categoria" class="control-label  requiredField">
                Categoria<span class="asteriskField">*</span></label><div class="controls "><select class="select form-control" id="id_categoria" name="categoria"><option value="4">Celular</option><option value="5">TV</option><option value="6">Computador</option></select></div></div><div id="div_id_orcamento" class="form-group"><label for="id_orcamento" class="control-label  requiredField">
                Preço máximo<span class="asteriskField">*</span></label><div class="controls "><input class="numberinput form-control" id="id_orcamento" name="orcamento" step="any" type="number" /> </div></div>

    <input type="submit" value="Enviar" />
</form>


    </div>

Upvotes: 4

Views: 1903

Answers (1)

Alasdair
Alasdair

Reputation: 309089

Make sure you are using the crispy form tag, not the crispy form filter.

{% load crispy_forms_tags %}
{% crispy form %}

Where form is the name of the form in the template.

Upvotes: 6

Related Questions