仅当字段为空时才用今天的日期填写 Acrobat 表单日期字段
Acrobat 表单的目标是在用户打开表单时用今天的日期填充日期字段(“MeetingDate”)。如果用户按原样保存表单并在几天后打开它,则旧日期应该仍然存在,而不是被当前日期替换。如果用户更改字段中的日期,则应保存该日期,并且稍后打开表单时不应替换该日期。
我有一个日期字段(“MeetingDate”)的自定义计算脚本,它可以完成所有这些操作,但有一个问题:
if (event.value != "")
then
event.value = util.printd ("m/d/yyyy", new Date())
endif
这种方法运行良好,只是在输入脚本后,今天的日期会填充 MeetingDate 字段并保存该值。这是有道理的,但我希望当用户打开表单时,该字段自动填充为今天的日期。相反,如果用户明天(2010 年 7 月 16 日)打开表单,则该字段中将显示 7/15/2010,因为这是我保存表单的日期。
我认为答案可能是输入脚本作为文档 JavaScript(高级 | 文档流程 | 文档 JavaScript),因为文档脚本在打开表单时执行,但我所有的尝试都会导致用户输入的日期在打开时被覆盖。几天后打开表格。 感谢的帮助!
The goal is for an Acrobat form to fill a date field ("MeetingDate") with Today's date when the user opens it. If the user saves the form as is and opens it a few days later, the old date should still be there, not replaced by the current date. If the user changes date in the field, that date should be saved and should not be replaced when the form is opened later.
I have a Custom Calculation Script for a date field ("MeetingDate") that does all of this, but with one problem:
if (event.value != "")
then
event.value = util.printd ("m/d/yyyy", new Date())
endif
This works well except that after entering the script, today's date fills in the MeetingDate field and the value is saved. That makes sense, but I want the field to be automatically filled with Today's date when the user opens the form. Instead, if the user opens the form tomorrow (7/16/2010) it will have 7/15/2010 in the field because that is the date I saved the form.
I think the answer may be to enter a script as a Document JavaScript (Advanced | Document Process | Document JavaScripts), since Document scripts execute when the form is opened, but all my attempts cause a date entered by the user to be overwritten when the form is opened days later. Thanks for the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
删除您的脚本并将其替换为以下文档 javascript:
保存您的表单并打开它,日期应该就在其中弹出。
制作文档 javascript 时,请记住不要将其放在函数中。一种方法如下。在 Acrobat 菜单中:
Remove your script and replace it with the following document javascript:
Save your form and open it, and the date should pop right in there.
When making the document javascript, remember to not put it inside a function. One way of doing that is the following. In the Acrobat menu:
希望您不介意我为英国用户(以及像我这样的新手)添加此代码编辑。
此代码填充日期字段,如下所示...
Hope you don't mind if I add this edit of your code for British users (and newbies like me)
This code fills the date field as follows...
@wells-anderson
你只需要删除 if 语句:
@wells-anderson
You just need to remove the if statement:
不幸的是,当我添加
var f = this.getField("DatepPrinted");
if (!f.value) f.value = util.printd("dd/mmmm/yyyy", new Date());
对于我在表单上的自定义击键,它返回“0”而不是 2015 年 4 月 2 日……有人知道为什么吗?
Unfortunately, when I add
var f = this.getField("DatepPrinted");
if (!f.value) f.value = util.printd ("dd/mmmm/yyyy", new Date());
to my custom keystroke on a form it gives me back "0" instead of 02-april-2015..anyone know why?