0

I'm in the process of building a number of forms using Sitecore Forms in Sitecore 9.0. All of the forms will be displayed in a modal dialogue, and all forms will show a thank you message, using the approach discussed here:

http://www.apiqu.com/blog/2018/August/sitecore-9-forms-thank-you-message

On closure of the modal dialogue I would like to reset the form so that it can be used again.

I have tried a number of approaches but none of them work, including:

Adding a hidden previous (submit) button to the final page of the form (where it displays the thank you), and using JavaScript to the click that and then using a js timer to wait until the form loads and then resetting the form using js. However 2 things happened:

  • The original data entered is what the form gets reset to.
  • When submitting the form, it updates the original record in the forms db rather than creating a new one

Is there an ajax call or js method I can call to reload and reset the form?

N.B. Just to be clear; this question is not a js/jQuery question but is a Sitecore forms related question.

Any thoughts or help would be much appreciated.

  • How is the modal loaded? Is the HTML for them form pre-loaded in the page before it's opened, or is it possible to render it upon modal open? – Amir Setoudeh Feb 1 at 18:42
  • This is Sitecore forms. Think improved WFFM – jwsadler Feb 2 at 19:27
-1

On the modal close js code, simply use jQuery or js to reset the form. For example, if your form is enclosed in a div like this:

<div class="form-container">
    <form>...Sitecore Form....</form>
</div>

You could do this:

jQuery:

$(".form-container form").trigger("reset")

JavaScript:

document.getElementsByClassName("form-container")[0].getElementsByTagName("FORM")[0].reset()

Obviously, dependeing on your HTML structure, you'll probably want to change and clean that up a little. That is just for demonstration purposes.

|improve this answer|||||
  • Thanks Amir, but unfortunately this won't work with Sitecore forms, this is because as you step through the forms pages, the fields are not persisted. As you will see from the above, I already attempted what you suggest with a more elaborate mechanism to try and load the initial form page first, but this didn't work because a) it resets back to the entered values not the defaults and b) when you submit the form again it updates the existing record rather than creates a new one. – jwsadler Jan 31 at 19:21
  • I've edited my original question to explain better – jwsadler Jan 31 at 19:24
  • @jwsadler. Sorry for the misunderstanding. I thought you were referring to the form elements. I presume now that you're referring to getting back to the initial state/page of the Sitecore form. I'll ask some additional questions on the initial question to see if we can find a different way. – Amir Setoudeh Feb 1 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.