django-formtools icon indicating copy to clipboard operation
django-formtools copied to clipboard

Error handling in done()

Open dbrgn opened this issue 8 years ago • 10 comments

Is there a way to handle errors in done() so that the form data in the storage is not cleared?

If the processing fails, I want to offer the user a possibility to re-process the data without having to re-fill the entire form.

dbrgn avatar Mar 22 '16 08:03 dbrgn

If I'm reading the source code correctly, a way to do this would be to catch ValidationErrors (or something like that) in the render_done method and render an error page containing that message. The template name of that error page could be specified as an instance attribute.

dbrgn avatar Mar 22 '16 08:03 dbrgn

I would like this feature too! In my application, we have to submit an API request at the end of the wizard that contains all the data. If that fails, I would like to have the data still in the forms so that the user can update according to the response from the API

eagle-r avatar May 17 '17 04:05 eagle-r

Hey!

Can you provide a working peace of code with done? Is not being called on my app :_(

guillenotfound avatar Aug 31 '17 18:08 guillenotfound

@ZiFFeL1992 What exactly are you looking for?

eagle-r avatar Sep 01 '17 00:09 eagle-r

@eagle-r I manage to get it working, thanks anyway :)

guillenotfound avatar Sep 02 '17 11:09 guillenotfound

@ZiFFeL1992 Do you consider this an open issue? If not, you should close it.

schinckel avatar Feb 23 '18 06:02 schinckel

Hey! Sorry for the delay, it has been so much time since I use this so I don't really remember what's wrong...

guillenotfound avatar Mar 03 '18 11:03 guillenotfound

I still feel this is would be a valuable feature. For my application, I ended up using an approach similar to that suggested by @dbrgn in https://github.com/django/django-formtools/issues/61#issuecomment-199702599.

This worked quite well for me but for it to work with the current codebase, I had to copy/paste the entire render_done() method and then modify it to catch a ValidationError raised by the done() method. Something along the lines of the code below. It's not very elegant and is specific to my requirements but it should give you an idea,

        try:
            done_response = self.done(final_forms.values(), form_dict=final_forms, **kwargs)
            self.storage.reset()
            return done_response
        except ValidationError as e:
            form.add_error(None, e)
            return self.render(form)

eagle-r avatar Mar 08 '18 12:03 eagle-r

Hi, I am having the same problem as discussed here and am wondering whether it would be possible to allow for handling errors in done(). At the very least, I need something sensible to happen instead of sending a 5xx to the user.

holtgrewe avatar Jun 21 '18 08:06 holtgrewe

I still feel this is would be a valuable feature. For my application, I ended up using an approach similar to that suggested by @dbrgn in #61 (comment).

This worked quite well for me but for it to work with the current codebase, I had to copy/paste the entire render_done() method and then modify it to catch a ValidationError raised by the done() method. Something along the lines of the code below. It's not very elegant and is specific to my requirements but it should give you an idea,

        try:
            done_response = self.done(final_forms.values(), form_dict=final_forms, **kwargs)
            self.storage.reset()
            return done_response
        except ValidationError as e:
            form.add_error(None, e)
            return self.render(form)

This works like a charm

HenryMehta avatar Sep 11 '19 08:09 HenryMehta