Copy link to clipboard
Copied
This is a different dialog box, so I'm starting a new thread.
Using the code from the API, I figured out part of the modification needed, but I need one more piece.
Here is the code I have:
var dialog2 = {
initialize: function (dialog) {
// Create a static text containing the current date.
var todayDate = dialog.store()["date"];
todayDate = "Date: " + util.printd("mmmm dd, yyyy", new Date());
dialog.load({ "date": todayDate });
},
commit:function (dialog) { // called when OK pressed
var results = dialog.store();
// Now do something with the data collected,
getField("Date1").value = results["dbeg"] + "-" + results["dend"];
},
description:
{
name: "Day(s) Served", // Dialog box title
align_children: "align_left",
width: 350,
height: 200,
elements:
[
{
type: "cluster",
name: "Day(s)",
align_children: "align_left",
elements:
[
{
type: "view",
align_children: "align_row",
elements:
[
{
type: "static_text",
name: "Begin Date: "
},
{
item_id: "dbeg",
type: "edit_text",
alignment: "align_fill",
width: 300,
height: 20
}
]
},
{
type: "view",
align_children: "align_row",
elements:
[
{
type: "static_text",
name: "End Date: "
},
{
item_id: "dend",
type: "edit_text",
alignment: "align_fill",
width: 300,
height: 20
}
]
},
{
type: "static_text",
name: "Date: ",
char_width: 25,
item_id: "date"
},
]
},
{
alignment: "align_right",
type: "ok_cancel",
ok_name: "Ok",
cancel_name: "Cancel"
}
]
}
};
What I would like to do is add a check so that if the beginning date and ending date are a single day (the same day (14, for example)), it only displays 14, rather than 14-14.
It would be seriously cool if I could use a calendar control to do this in the dialog box, but I only need to display the day(s) and not the month or year.
Any of this code I don't need I can delete, but I don't know which of the brackets need to be deleted or kept, as I keep getting errors when trying to do so.
I am going to assume I need to copy this document level script 17 more times to cover all 18 fields, which will each have a different value or be null.
If there is a better way to do this, I'm open to uggestions. The custom dialog boxes do not work on mobile, even in PDF Expert.
I thought about using list boxes for the number selections, but can't figure out how to modify the sample code and doesn't look like it would really work.
Thanks again.
Copy link to clipboard
Copied
Here's a good suggestion to add a script to multiple field objects instead of manually copying:
As to obtain days between two dates see this mini example:
The code that I'm using in one of my forms:
var strStart = this.getField("first.DATE").value;
var strEnd = this.getField("last.DATE").value;
var dateStart = util.scand("dd mmmm yyyy", strStart);
var dateEnd = util.scand("dd mmmm yyyy", strEnd);
var diff = dateEnd.getTime() - dateStart.getTime();
var oneDay = 24 * 60 * 60 * 1000;
var days = Math.floor(diff/oneDay);
x = days;
event.value = x+1;