Copy link to clipboard
Copied
Please forgive me as my brain seems to be turned off right now...
I'm not looking for the answer per se. I'm just looking to get pointed to the right AcroForm method.
I have a multiline text field that I'd like to populate instances of a string of text based on the numeric value of another field. I'm drawing a blank on the logic to even start.
The form needs to add up to 9 instances.
if a numeric field's value is 1-9, it will place the same number of string instances as the numeric field's value in a multiline text field.
Example:
var tString = "I'm a text string";
for(var i = 1; i < 10; i++) {
if(numericField.value == i) {
multilinefield.value = tString * i;
}
}
Example: numericField value is 3
Expected Result:
I'm a text string
I'm a text string
I'm a text string
Copy link to clipboard
Copied
Try this script as custom calculation script of multiline field (change name of "numericField" if necessary:
var x = this.getField("numericField").value;
var tString = "I'm a text string";
function Rstring(str, num) {
var rSTR = "";
while (num > 0) {
rSTR += str;
num--;}
return rSTR;}
event.value = Rstring(tString+"\n", x);
Copy link to clipboard
Copied
Some pointers:
- Set the value of the numericField (having converted it to a Number) as the upper-limit of the for-loop.
- Reset the value of the target field at the start of the code.
- Add the strings to the current value of the target field in the loop, don't assign them as the new value, as that overwrites the old one.
[Edited for clarity]
Copy link to clipboard
Copied
Thanks for the pointers.
I'm not quite sure what you mean by converting to a number.
There's the Number method or the number format... I also don't understand why.
var numField = Number(getField("numericalField").value);
OR
numericalField.setAction(Format, "AFNumber_Format());
On a side note, I've never been able to find any documentation on AFNumber_Format(). I don't know what the parameters are. I know that AFNumber_Format(2,0,0,0,$,true); will format a field to have a currency symbol and two decimal places. By deduction, I'm assuming the "2" is the decimal parameter.
Since June it's been hard to reference the new SDK site. I had all these links to it saved in bookmarks that no longer work, and I can't seem to find anything. I downloaded all of the 2021 pdfs, but the find tool doesn't do that well IMO. Did Adobe make it primarily a pdf download?
For clarity, your first pointer would be to set the value of the numericField to 9 (upper limit)? Wouldn't that make the script populate 9 times?
This is likely going to be a calculation script and will be based on the value of the numericField. The numericField will be hidden by default and triggered to show and set to required on a combobox selection set to be committed immediately. The user will then enter the product quantity they need.
Copy link to clipboard
Copied
I mean the former.
AFNumber_Format is an internal function of Acrobat, and not a part of the Acrobat SDK, so you won't find it there anyway. I agree that the online version of the SDK is terrible. I only use the PDF version.
If you search for it online you will find some more information about it.
Copy link to clipboard
Copied
Try this script as custom calculation script of multiline field (change name of "numericField" if necessary:
var x = this.getField("numericField").value;
var tString = "I'm a text string";
function Rstring(str, num) {
var rSTR = "";
while (num > 0) {
rSTR += str;
num--;}
return rSTR;}
event.value = Rstring(tString+"\n", x);
Copy link to clipboard
Copied
I'm getting part of this to work, but I want to increment the value of whatever num is to each instance of the string.
Example: num is 3
I want:
TV1:
TV2:
TV3:
I've experiemented with for loops, etc to try to connect num to an increment and am at a loss nor know the proper terminology to be able to google what I'm looking for.
Perhaps something simple like var i =1 "Apple TV " + i++ + "rest of string";? Should I define an integer to base it off of? Should I follow Try67's suggestion of converting the numeric field's value to a number? I'm not sure how that would play out inside a parameter in a function. There's also actually two different numeric fields.
Lastly, I tried to keep whatever is in the multiline field there, but it seems to delete it based on whatever the numeric field is. I haven't gotten to that to start to fix it, but I initially tried by using boolian logic to search for it. The first thing I was going to try is change !event.value to event.value == ""...
var x = this.getField("tvs.num").value;
var y = this.getField("box.num").value;
var dApple;
var dSat;
var dLight;
var dShade;
function Rstring(str, num) {
var rSTR = "";
while (num > 0) {
rSTR += str;
num--;
dApple = "Apple TV " + num + ": \nModel: xxx\nPhysical Location: xxx\nDevice Plugged Into: xxx\nHDMI Input: xxx\n";
dSat = "Satellite " + num + ": \nModel: xxx\nPhysical Location: xxx\nDevice Plugged Into: xxx\nHDMI Input: xxx\n";
dLight = "Light " + num + ": \nName: xxx\nPhysical Location: xxx\nCircuit Number: xxx\n";
dShade = "Shade " + num + ": \nName: xxx\nPhysical Location: xxx\nCircuit Number: xxx\n";
}
return rSTR;
}
if(service.value == "Apple TV(s)") {
if(!event.value || event.value.indexOf("Model:") || event.value.indexOf("Name:")) {
event.value = Rstring(dApple + "\n", x);
}
else {
event.value = details.value + "\n" + Rstring(dApple + "\n", x);
}
}
else if(service.value == "DirecTV to Dish") {
if(!event.value || event.value.indexOf("Model:") || event.value.indexOf("Name:")) {
event.value = Rstring(dSat + "\n", x);
}
else {
event.value = details.value + "\n" + Rstring(dSat + "\n", x);
}
}
else if(service.value == "Add/Change Light Circuit(s)") {
if(!event.value || event.value.indexOf("Model:") || event.value.indexOf("Name:")) {
event.value = Rstring(dLight + "\n", y);
}
else {
event.value = details.value + "\n" + Rstring(dLight + "\n", y);
}
}
else if(service.value == "Add/Change Shade Circuit(s)") {
if(!event.value || event.value.indexOf("Model:") || event.value.indexOf("Name:")) {
event.value = Rstring(dShade + "\n", y);
}
else {
event.value = details.value + "\n" + Rstring(dShade + "\n", y);
}
}
Copy link to clipboard
Copied
by the way, the strings with + num + in them return 0 for all when a number is input.
Copy link to clipboard
Copied
Here's a couple of variations of for loops I tried:
for (var i = 1; i >= num.length; i++) {
var dApple = "Apple TV " + i + ": \nModel: xxx\nPhysical Location: xxx\nDevice Plugged Into: xxx\nHDMI Input: xxx\n\n";
var dSat = "Satellite " + i + ": \nModel: xxx\nPhysical Location: xxx\nDevice Plugged Into: xxx\nHDMI Input: xxx\n\n";
var dLight = "Light " + i + ": \nName: xxx\nPhysical Location: xxx\nCircuit Number: xxx\n\n";
var dShade = "Shade " + i + ": \nName: xxx\nPhysical Location: xxx\nCircuit Number: xxx\n\n";
}
for (var i = 1; i >= num.length; i++) {
var dApple = "Apple TV " + num[i] + ": \nModel: xxx\nPhysical Location: xxx\nDevice Plugged Into: xxx\nHDMI Input: xxx\n\n";
var dSat = "Satellite " + num[i] + ": \nModel: xxx\nPhysical Location: xxx\nDevice Plugged Into: xxx\nHDMI Input: xxx\n\n";
var dLight = "Light " + num[i] + ": \nName: xxx\nPhysical Location: xxx\nCircuit Number: xxx\n\n";
var dShade = "Shade " + num[i] + ": \nName: xxx\nPhysical Location: xxx\nCircuit Number: xxx\n\n";
}
Copy link to clipboard
Copied
I was able to get what I needed based on the script you provided.
Here's the code that was put in a blur event of two separate fields:
//blur event field 1
var y = this.getField("box.num").value;
function lsString(num) {
var rSTR = "";
var i = 1;
while (num > 0) {
if(service.value == "Add/Change Light Circuit(s)") {
var cLight = "Light " + i + ": \nName: xxx\nPhysical Location: xxx\nCircuit Number: xxx\n\n";
rSTR += cLight;
}
else if(service.value == "Add/Change Shade Circuit(s)") {
var cShade = "Shade " + i + ": \nName: xxx\nPhysical Location: xxx\nCircuit Number: xxx\n\n";
rSTR += cShade;
}
num--;
i++;
}
return rSTR;
}
if(service.value == "Add/Change Light Circuit(s)" || service.value == "Add/Change Shade Circuit(s)") {
details.value = lsString(y) + "\n";
if(!event.value) {
details.value = details.value;
this.getField("info").value = "";
}
else {
this.getField("info").value = "Changing the number of circuits after manually entering text in the details box will delete all manual text entries. Ensure there aren't changes to be made prior to editing.";
}
}
//blur event field 2
var x = this.getField("tvs.num").value;
function tvString(num) {
var rSTR = "";
var i = 1;
while (num > 0) {
if(service.value == "Apple TV(s)") {
var tvApple = "Apple TV " + i + ": \nModel: xxx\nPhysical Location: xxx\nDevice Plugged Into: xxx\nHDMI Input: xxx\n\n";
rSTR += tvApple;
}
else if(service.value == "DirecTV to Dish") {
var tvSat = "Satellite " + i + ": \nModel: xxx\nPhysical Location: xxx\nDevice Plugged Into: xxx\nHDMI Input: xxx\n\n";
rSTR += tvSat;
}
num--;
i++;
}
return rSTR;
}
if(service.value == "Apple TV(s)" || service.value == "DirecTV to Dish") {
details.value = tvString(x) + "\n";
if(!event.value) {
details.value = details.value;
this.getField("info").value = "";
}
else {
this.getField("info").value = "Changing the number of TVs after manually entering text in the details box will delete all manual text entries. Ensure there aren't changes to be made prior to editing.";
}
}

