error field not showing in django crispy forms?

397 Views Asked by At

Here is my form class:

class VinForm(forms.Form):
    VIN = forms.CharField(min_length=13,max_length=13, label='VIN')

    def __init__(self, *args, **kwargs):
        super(VinForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_method = 'post'
        self.helper.form_class = 'form-horizontal col-xs-12 col-md-6 col-lg-5'
        self.helper.label_class = 'col-xs-3 col-md-3 col-lg-3'
        self.helper.field_class = 'col-xs-12 col-md-12 col-lg-12'

        self. helper.layout = Layout(
            Fieldset(
                'Get vehicle info',
                Field('VIN', autofocus=True, placeholder='JN1HJ01F8RT231164'),
            ),
            FormActions(
                Submit('submit', 'get vehicle info'),
            ),
        )

Please note that I'm not using a ModelForm since there is no need for it. When I enter 3 digits for the VIN it should show an error. Currently it is not showing any error. How can I fix this?

Here is my rendering in template:

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

my view:

class HomePageView(FormView):
    success_url = '/dashboard/'
    template_name = 'home.html'
    form_class = VinForm

    def get_context_data(self, **kwargs):
        context = super(HomePageView, self).get_context_data(**kwargs)
        context['vehicle_count'] = 1234  #Glucose.objects.count()
        form =  VinForm()
        context['form'] = form
        return context
0

There are 0 best solutions below