We are trying to load a sitecore Form on Modal. On submit, Form goes from "Page1" to a "Page2" using "go to" action on submit button condition. On Closing of the modal, Form must refresh and show "Page1" without reloading the whole page. Is there any way to achieve this scenario ??
3 Answers
First, when it comes to modals with forms rendered within them, one should consider the following:
- Which actions can trigger a close of the modal?
- A close button?
- Form submit?
- Clicking outside of the modal?
- Hotkey (eg. ESCAPE key)?
- Is it easy for a user to accidentally close the modal and potentially lose their form progress?
- If a modal is closed and reopened, should it preserve the state that existed prior to the close action?
- What if a form is only partially complete and a close action occurs? Should the user be notified that the form is in progress and be forced to confirm that they want to close the modal?
- What if a manual page refresh event is encountered?
In your case, it sounds like you have a modal with a form that has two pages, and that you are ostensibly handling the case in which a user submits the form, is shown the second form page (perhaps a "thank you for submitting" page), and you want to ensure that when the modal is closed, the form state is cleared and that the first page of the form is shown again, should the user open up the modal again without refreshing the page.
Depending on your UX requirements, one idea would be to render the form in an iframe. You would then have the ability to destroy the iframe element on modal close and have it render again on open.
If you want to do any communication between your webpage and the iframe, consider looking into window.postMessage()
(docs).
Well, it's not so simple and might be a little complex but I think there's a way that might work:
- Add a new class to the Submit button on the Form, such as
form-submission
- Attach an Event for the class (
form-submission
) using JavaScript - This event will trigger, via
Ajax
, a method from yourController
. - In the Controller you render just the modal.
- The Ajax receives the View from the Controller as a result of the call done in step 3.
- Replace the current Modal, with the new Modal returned by the Ajax call.