Conditional logic for rendering django messages via message-box vs new modal #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This branch represents an improved version of the current PR "Contact Form Feedback as Modal Issue#357" found here
This branch does not break slim.html and will properly render the Contact form stuff as a modal, and everything else as a message-box.
Per-File Changes (diffs vs main)
contact/templates/contact/contact.html
Added HTML structure for modal. This is copied (and adapted classnames) from the existing modal implementation for the navbar's "Login" button. This HTML conditionally renders depending on whether or not there is a message to display.
The modal will {% include "_messages.html" %} in order to get the success/failure message.
The button to close the modal has an "onclick" function which takes the user to the Home page.
contact/views.py
The ContactView itself now redirects to itself (/contact) for the purpose of displaying the modal. The modal button then redirects the user Home.
Added two things:
message_as_modal = True
so that we can tell the template to render the message as a modalget_context_data
, which is what we use to communicate variables from the View over to the template. Here I've just added themessage_as_modal
value to the context dictionary.chipy_org/templates/_messages.html
Added an if-statement. If message_as_modal is True, then return the message that the modal wants. Otherwise, do what it was already doing (render the message-box exactly how it was).
chipy_org/templates/shiny/slim.html
I've reverted my change that initially broke the message-boxes!
Two (small) new changes:
message_as_modal
is NOT set to True.