javascript Apex - 离开页面时清除表单(也在重定向时)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33530567/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 16:36:52  来源:igfitidea点击:

Apex - Clear form when leaving page (also on redirect)

javascriptplsqloracle-apex

提问by PidgeyBAWK

Currently, if I populate a form and leave the page, the form entries will still be present when I return to the form. Is it possible to prevent these entries from being saved?

目前,如果我填充表单并离开页面,当我返回表单时,表单条目仍然存在。是否可以防止保存这些条目?

The items' default values are populated using PS/SQL, but the content can be adjusted.

项目的默认值使用 PS/SQL 填充,但内容可以调整。

I tried creating a dynamic action to clear the items on 'Page Unload', but this didn't do anything. Is this the correct browser event, or did I simply get the implementation wrong?

我尝试创建一个动态操作来清除“页面卸载”上的项目,但这没有任何作用。这是正确的浏览器事件,还是我只是把实现弄错了?



Update:To provide a bit of context...

更新:提供一些上下文......

Pages:

页数:

  1. Home
  2. Form
  3. DML Form (insert) - I want any modifications to not be stored
  1. 形式
  2. DML 表单(插入)-我希望不存储任何修改

Page 3 can be accessed via Page 1 or Page 2.

可以通过第 1 页或第 2 页访问第 3 页。

If the user accesses the form via Page 2 (a different form), they will have selected a specific value and this is used to populate default values on Page 3 (via item and PL/SQL Function Body).

如果用户通过页面 2(一个不同的表单)访问表单,他们将选择一个特定的值,这将用于填充页面 3 上的默认值(通过项目和 PL/SQL 函数体)。

If the user accesses the form via Page 1, the same PL/SQL will run - this may result in Page 3 form items being empty (NULL default values).

如果用户通过第 1 页访问表单,将运行相同的 PL/SQL - 这可能导致第 3 页表单项为空(NULL 默认值)。

HOWEVER, when the user edits Page 3 items (changing from default values), these values will persist when the user next accesses the form. How can I prevent this state from being captured?

但是,当用户编辑第 3 页项目(从默认值更改)时,这些值将在用户下次访问表单时保持不变。如何防止这种状态被捕获?

回答by Tom

You will need to clear the cache of the page. This will clear the session state of the items on the page and thus result in items being empty once again.
You may need to add this clear on several locations. If you have used column links to access the page, buttons with redirects, branches, etc. The apex URL has a part which states which pages have to be cleared, and you can generally define this clearing of a page cache declaratively. Link builder apex 5

您将需要清除页面的缓存。这将清除页面上项目的会话状态,从而导致项目再次为空。
您可能需要在多个位置添加此清除。如果您使用列链接访问页面、带有重定向的按钮、分支等。顶点 URL 有一部分说明必须清除哪些页面,您通常可以声明性地定义页面缓存的这种清除。 链接生成器顶点 5

You can also create processes where you can define which page (or pages) has to be cleared. For example, if you always want the cache to be cleared when entering the page, no matter where you came from, you could add a process on the page doing just that.
Process type apex 5Session state is ultimately what is causing this behavior: go to the page, change some things, page gets submitted for whatever reason and causes session state to be saved.
Usually, on DML forms generated through the wizard, the cache would only be cleared when using the "create" button coming from another location (usually the overlying report).

您还可以创建流程,您可以在其中定义必须清除的页面(或页面)。例如,如果您总是希望在进入页面时清除缓存,无论您来自何处,您都可以在页面上添加一个进程来执行此操作。
工艺类型顶点 5会话状态最终是导致这种行为的原因:转到页面,更改某些内容,页面因任何原因被提交并导致会话状态被保存。
通常,在通过向导生成的 DML 表单上,只有在使用来自另一个位置(通常是上层报告)的“创建”按钮时才会清除缓存。

Here is the (apex 5.0) documentation on session state and managing it.

这是有关会话状态和管理它的(apex 5.0)文档。

回答by Iliyan Yotov

You can do it with something like this, but first you need to add jQuery to your page. I recommend using a content delivery network (CDN). You can edit the code to clear the value in your type of forms. I hope this could help you!

您可以使用类似的方法来实现,但首先您需要将 jQuery 添加到您的页面。我建议使用内容交付网络 (CDN)。您可以编辑代码以清除表单类型中的值。我希望这可以帮助你!

jQuery CDN example

jQuery CDN 示例

$(document).ready(function() {
    $("body")
        .find("input").val("")
        .end()
        .find("select").val("-")
        .end()
        .find("textarea").val("");
    };
});