Skip to main content
Participant
August 7, 2025
Answered

Multifield Dialog not working correctly - Dynamic Stamp

  • August 7, 2025
  • 1 reply
  • 370 views

Hello All!

I’ve developed a dynamic stamp in Acrobat that successfully generates a unique ID, prompts the user to "check boxes" aka. Textfields that are populated with an X if the respective value is input, and collects text input for fields, each via separate dialogs or prompts. However, I’m struggling to combine the text field prompts into a single multi-field dialog for a smoother user experience.

First I wanted to work out only the text fields and when that works, the goal would be to also have thge "checkboxes" in the same dialog (not a must)

Has anyone managed to implement this, or can offer advice?

 

What works:

1. Calculate an unique ID-number for each stamp.  A trusted function handles incrementing and saving a counter. The stamp script then reads this value each time the stamp is applied. (✓) 

2. Prompt user for checking boxes. A dialog prompts the user to choose "a" or "b", and the script marks the matching checkbox aka textfield with an "X".  (✓) 

3. Prompt user individually for each field with app.response (✓) 

 

--------------------------

Now this kindoff works. But it only inputs the last value "reference" and the other fields stay undefined. I'm assuming that my script saves only one value and overrides the others? Where is the mistake?

 

if (event.source && event.source.forReal && event.source.stampName == "#SampleStamp") {
var formData = {};

var formDialog = {
initialize: function(dialog) {},
validate: function(dialog) {
var store = dialog.store();
return (store["category"] !== "" && store["type"] !== "" && store["title"] !== "" && store["reference"] !== "");
},
commit: function(dialog) {
console.println("Dialog store: " + JSON.stringify(dialog.store()));
var store = dialog.store();
formData.category = store["category"];
formData.type = store["type"];
formData.title = store["title"];
formData.reference = store["reference"];
},
description: {
name: "Enter Form Data",
type: "cluster",
align_children: "align_left",
elements: [{
type: "view",
align_children: "align_column",
elements: [{
type: "view",
align_children: "align_row",
elements: [{
type: "static_text",
name: "Category:",
width: 100
},
{
item_id: "category",
type: "edit_text",
alignment: "align_fill",
width: 250,
height: 20
}]
},
{
type: "view",
align_children: "align_row",
elements: [{
type: "static_text",
name: "Type:",
width: 100
},
{
item_id: "type",
type: "edit_text",
alignment: "align_fill",
width: 250,
height: 20
}]
},
{
type: "view",
align_children: "align_row",
elements: [{
type: "static_text",
name: "Title:",
width: 100
},
{
item_id: "title",
type: "edit_text",
alignment: "align_fill",
width: 250,
height: 20
}]
},
{
type: "view",
align_children: "align_row",
elements: [{
type: "static_text",
name: "Reference:",
width: 100
},
{
item_id: "reference",
type: "edit_text",
alignment: "align_fill",
width: 250,
height: 20
}]
}]
},
{
item_id: "ok",
type: "ok_cancel",
alignment: "align_right",
ok_name: "OK",
cancel_name: "Cancel"
}]
}
};

var result = app.execDialog(formDialog);

// Debug output
console.println("formData: " + JSON.stringify(formData));

if (result === "ok") {
var fields = ["category", "type", "title", "reference"];
for (var i = 0; i < fields.length; i++) {
var f = this.getField(fields[i]);
if (f) {
f.value = formData[fields[i]];
} else {
console.println("Field not found: " + fields[i]);
}
}
} else {
app.alert("Dialog cancelled.");
}
}

Correct answer Bernd Alheit

Use only 4 characters for item_id. 

1 reply

Bernd Alheit
Community Expert
Bernd AlheitCommunity ExpertCorrect answer
Community Expert
August 7, 2025

Use only 4 characters for item_id. 

Participant
August 7, 2025

Oh that was unexpected but luckily makes so much sense, since the only value that went through had 4 characters. Thank You!

 

 

I have a field that needs to store numeric values...right now reading through the JS API but haven't found a solution yet. Any quick recommendation or solution perhaps? 

 

try67
Community Expert
Community Expert
August 7, 2025

You can't limit the user's input like you can with a regular field, but you can reject an incorrect value in the validate function of the dialog. Return false if the value of the field is not numeric, and the dialog won't close until the user fixes it (or cancel out of it).