Skip to content
This repository has been archived by the owner on Nov 27, 2020. It is now read-only.

Redirect back with errors #133

Merged
merged 6 commits into from
Nov 25, 2019
Merged

Redirect back with errors #133

merged 6 commits into from
Nov 25, 2019

Conversation

dsamojlenko
Copy link
Member

@dsamojlenko dsamojlenko commented Nov 23, 2019

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.

@timarney timarney temporarily deployed to cds-node-starter-pr-133 November 23, 2019 21:48 Inactive
@dsamojlenko dsamojlenko temporarily deployed to cds-node-starter-pr-133 November 25, 2019 16:47 Inactive
changelog.md Show resolved Hide resolved
@dsamojlenko dsamojlenko temporarily deployed to cds-node-starter-pr-133 November 25, 2019 16:56 Inactive
@dsamojlenko dsamojlenko temporarily deployed to cds-node-starter-pr-133 November 25, 2019 16:59 Inactive
errors: errorArray2ErrorObject(errors),
})
req.session.flashmessage = errorArray2ErrorObject(errors)
return res.redirect('back')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the code that checks this flash message? I think we need to load it into res.locals.errors for the form-control errors to work.

@jneen
Copy link
Contributor

jneen commented Nov 25, 2019

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
Copy link
Member Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants