仅当字段为空时才用今天的日期填写 Acrobat 表单日期字段

发布于 2024-09-10 06:56:09 字数 588 浏览 4 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

杀手六號 2024-09-17 06:56:09

删除您的脚本并将其替换为以下文档 javascript:

var f = this.getField("wells_datefield");
if (!f.value) f.value = util.printd ("m/d/yyyy", new Date());

保存您的表单并打开它,日期应该就在其中弹出。

制作文档 javascript 时,请记住不要将其放在函数中。一种方法如下。在 Acrobat 菜单中:

  1. 高级 -> 文档处理 -> 文档 Javascripts...
  2. 在弹出的对话框中,输入脚本名称(例如“populate_date”),然后单击添加...
  3. 在弹出的脚本对话框中:删除所有内容(“function populate_date(){}”)并粘贴到上面的脚本中。
  4. 单击“确定”,然后单击“关闭”。
  5. 保存表单,关闭它并重新打开它。
  6. 没有第6步! :>

Remove your script and replace it with the following document javascript:

var f = this.getField("wells_datefield");
if (!f.value) f.value = util.printd ("m/d/yyyy", new Date());

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:

  1. Advanced->Document Processing->Document Javascripts...
  2. In the dialog that pops up, enter a Script Name (for instance "populate_date") and click Add...
  3. In the script dialog that pops up: REMOVE everything ("function populate_date(){}") and paste in the script above.
  4. Click ok, then Close.
  5. Save the form, close it and reopen it.
  6. There is no step 6! :>
疧_╮線 2024-09-17 06:56:09

希望您不介意我为英国用户(以及像我这样的新手)添加此代码编辑。

var f = this.getField("date");
if (!f.value) f.value = util.printd ("dd/mmm/yyyy", new Date());

此代码填充日期字段,如下所示...

03/Jan/2013

Hope you don't mind if I add this edit of your code for British users (and newbies like me)

var f = this.getField("date");
if (!f.value) f.value = util.printd ("dd/mmm/yyyy", new Date());

This code fills the date field as follows...

03/Jan/2013
浮生未歇 2024-09-17 06:56:09

@wells-anderson

你只需要删除 if 语句:

event.target.value = util.printd("m/d/yyyy", new Date());

@wells-anderson

You just need to remove the if statement:

event.target.value = util.printd("m/d/yyyy", new Date());
花之痕靓丽 2024-09-17 06:56:09

不幸的是,当我添加
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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文