Monday, January 30, 2017

Re: form_invalid

Is just what i pictured. But when form_invalid is called?

Il giorno lunedì 30 gennaio 2017 02:35:54 UTC+1, Melvyn Sopacua ha scritto:

On Sunday 29 January 2017 04:10:20 Roberto Russi wrote:

> I need get data from a form when submit is clicked even if data are

> invalid, inconplete or empty.

> I try to override form_invalid in CreateView but it is never called

> and form_valid, obviously, only if data are valid.

> Why form_invalid is never called?

 

Because the form is blocked by client-side validation: it never gets to the server. If you watch the development console closely, you will see that when you press save, there is no incoming request.

 

Add the following clean method to DemoForm, fill in "bla" for demo_code in the form and you will see form_invalid being called.

 

def clean(self):
if self.data['demo_code'] != 'valid':
raise ValidationError('{}: Invalid demo code'.format(
self.data['demo_code']
))

--

Melvyn Sopacua

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/71fdcf25-d5ac-46a2-9e40-ce3eb3f3e1e3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment