Copy link to clipboard
Copied
Hello again.
I am trying to modify one of the code samples in the JavaScript API.
var dialog1 = {
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, for example,
console.println("Your name is " + results["fnam"]
+ " " + results["lnam"] );
},
description:
{
name: "Personal Data", // Dialog box title
align_children: "align_left",
width: 350,
height: 200,
elements:
[
{
type: "cluster",
name: "Your Name",
align_children: "align_left",
elements:
[
{
type: "view",
align_children: "align_row",
elements:
[
{
type: "static_text",
name: "First Name: "
},
{
item_id: "fnam",
type: "edit_text",
alignment: "align_fill",
width: 300,
height: 20
}
]
},
{
type: "view",
align_children: "align_row",
elements:
[
{
type: "static_text",
name: "Last Name: "
},
{
item_id: "lnam",
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 want to do is modify this part:
commit:function (dialog) { // called when OK pressed
var results = dialog.store();
// Now do something with the data collected, for example,
console.println("Your name is " + results["fnam"]
+ " " + results["lnam"] );
},
Instead of sending it to the console, I want to put that information in the "Name" Text box from which I am calling the results using the app.execDialog(dialog1); via Mouseup Action. This script is a document level script as I understand the example instructions and it is called Name. So when I click in the Name text field, I want to enter First Name and Last Name, and when I click OK button, the Name field is populated with "John Smith" and user tabs or hits enter to continue filling out the rest of the form.
I have tried several different things with no luck.
I don't necessarily need the Date portion of this sample script, though it is interesting. It would need to be modified a bit for my purposes, so like I said, it is optional at this point.
Thanks very much for a quick reply.
Copy link to clipboard
Copied
Replace this line:
console.println("Your name is " + results["fnam"] + " " + results["lnam"] );
With:
this.getField("Name").value = results["fnam"] + " " + results["lnam"];
Copy link to clipboard
Copied
Thanks. I was on the right track, but didn't get it quite right.
Copy link to clipboard
Copied
One more question. I am also using this script:
// Custom Format script for text field
if (!event.value) {
event.value = "Please enter your First and Last Name.";
event.target.display = display.noPrint;
} else {
event.target.display = display.visible;
}
The onFocus and OnBlur scripts to change the text properties do not work with MouseUp action that calls the document level script, so I am using the above code as a custom format script to blank the text field. So this is a two part question:
1. Is there as way to add code to commit the change immediately without the need to hit enter or tab away from the field first (like in a combobox)?
2. Is there a way to set the text properties in the document level script?
Thanks for all your help.
Copy link to clipboard
Copied
++Adding to the discussion,
I think you may be able to use MouseExit for that purpose, or even the combination of MouseDown and MouseEnter. But the document-level script need to use event.target.value instead of event.value or it will throw error.
Copy link to clipboard
Copied
this.getfield gave me an error, but getfield worked.
How do I remove the today's date bit at the top and the part where it displays it? I'm getting syntax errors when trying to remove the display Today's date part at the bottom of the script. There are so many brackets.
Copy link to clipboard
Copied
use getField, not getfield
Copy link to clipboard
Copied
I might have typed that.