cds-snc / node-starter-app

Quick start application setup.... because you have to start somewhere.
MIT License
5 stars 3 forks source link

Redirect back with errors #133

Closed dsamojlenko closed 4 years ago

dsamojlenko commented 4 years ago

Currently when posting a form with incomplete data, the validation helper takes over and re-renders the form with errors in place from the post route. This causes some problems, and is, I think, the root of the issue in #103

This will instead flash the error messages to the session, then redirect back to the form. Since the form re-renders as a regular GET request, it will have everything a GET request should have available to it. So this also solves the problem of page-specific js being lost on validation errors.

Had to adjust the test as well, since the response on an incomplete form request is now a 302 redirect instead of a 200 OK.

jneen commented 4 years ago

This is a really cool change! I'll have to integrate it with #132, but I'm missing where the integration point is - i.e. where that flash message is actually checked and rendered. cc @timarney

dsamojlenko commented 4 years ago

I think the magic happens in data.helpers.js ... when gathering the view data, it grabs anything in flash and assigns it to an errors object before passing to the view

image