Back Button Handle A Dynamic Form

后端 未结 6 1095
旧时难觅i
旧时难觅i 2020-12-28 17:17

I have a form with an array of text fields. The user (through javascript) can add an arbitrary number of text fields to the form. After submitting the form and pressing th

6条回答
  •  旧时难觅i
    2020-12-28 17:37

    Block the use of the back button. When the back button is pressed, rerender the previous page for the user with the new fields included, either visibly if that makes sense, or hidden. That way the user is able to use the back button normally and you have full control over the appearance of the ''previous'' page.

    In your specific use case, you just need to render the page with all the fields visible and filled in with the values that were submitted.

    This is a good pattern to follow for any wizard type of process where you provide a sequence of forms for the user to fill in and they may choose to go back to a previous form.

    To make it perfectly clear, I am suggesting that you use this advice on capturing the onUnload event to trigger form submission (so that you get the entered values) and to rerender the previous page that "back" would have displayed (without the values). The only alternative is to use Ajax to send the entered values every time that the user leaves a field, and then have every page check with the server via AJAX to retrieve additional values to display.

    Here are some additional pages that discuss taking control over the function of the back button and using the unload event to persist forms data:

    • Mastering the Back Button with Javascript
    • Don't Let the Door Hit You
    • Cross Browser unload Event and the Back Button
    • Persisting portlet forms data in WebSphere Portal V5.1

提交回复
热议问题