2

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.

4
  • 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? Commented Feb 1, 2020 at 18:42
  • This is Sitecore forms. Think improved WFFM
    – jwsadler
    Commented Feb 2, 2020 at 19:27
  • Any updates on this @jwsadler? Commented Sep 3, 2020 at 19:33
  • It would also be good to consider the state of the Request Verification Token if any session state has changed. Commented Sep 3, 2020 at 19:40

1 Answer 1

-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.

3
  • 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
    Commented Jan 31, 2020 at 19:21
  • I've edited my original question to explain better
    – jwsadler
    Commented Jan 31, 2020 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. Commented Feb 1, 2020 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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