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
No comments:
Post a Comment