Copy link to clipboard
Copied
I need to have the "Group name" auto populate based on the selections made from the previous 5 dropdown selections. If it stays on "Select one" I need it to not auto populate. Parent site, Subsite 1, and Type will always have a selection made while it is possible no selection is needed for Subsite 2 or 3. Also each selection ends in "-".
If the user selects the wrong dropdown choice and changes it, will the group name field detect the change and auto correct?
I am using Adobe Acrobat Pro 2017. My limited knowledge of JavaScript is based on this forum. I can usually find what I need searching from previous comments. Thank you for any help you can provide.
I would use an array variable to gather the values from the fields, filter out the "Select one" items, and then join the elements of the array for the "Group Name" field value;
// Custom calculation for the Group Name;
var aElements = new Array();
var aFields = new Array("Parent", "Sub1", "Sub2", "Sub3", "Type");
for(var i = 0; i < aFields.length; i++)
{
aElements.push(this.getField(aFields).value);
}
function NotSelectOne(value)
{
return value != "Select one";
}
var aCombined = aElements.filter(NotSelectOn
...Copy link to clipboard
Copied
So you just want its value to be the values of all other fields, combined?
Copy link to clipboard
Copied
Thank you for your reply.
So you just want its value to be the values of all other fields, combined? Yes, except when it stays on select one. I would like the “Select one” to be ignored.
Copy link to clipboard
Copied
1. Must all 5 fields be completed? No, it is possible subsite 2 and 3 are not needed.
So if any of the other fields has the default value selected, it should not display anything?
Copy link to clipboard
Copied
I'm adding a picture that might explain better. This is a sample of how the Group name field should look after selections are made. Please note that Subsite 3 remains on Select one and nothing is added in the Group name field for it.
Copy link to clipboard
Copied
You didn't answer my last question... What should happen if Sub1 is "Select One", for example?
Copy link to clipboard
Copied
Assuming you want the Group Name field to be empty in such a situation, you can use this code as its custom calculation script:
(function () {
var requiredFields = ["Parent", "Sub1", "Type"];
var optionalFields = ["Sub2", "Sub3"];
var values = [];
event.value = "";
for (var i in requiredFields) {
var f = this.getField(requiredFields);
if (f.valueAsString==f.defaultValue) {
return;
}
values.push(f.valueAsString);
}
for (var i in optionalFields) {
var f = this.getField(optionalFields);
if (f.valueAsString!=f.defaultValue) {
values.push(f.valueAsString);
}
}
event.value = values.join("");
})();
Copy link to clipboard
Copied
Thank you for the script. I do not want the Group Name to ever be empty. I have it where Parent Site is set for USA-DPT- so at the minimum it should always show USA-DPT-.
What should happen if Sub1 is "Select One", for example? If that happened then it would only show Parent and Type. The user would not need to enter Sub2 or Sub3. Example: USA-DPT-Calendar_ATM-
I also tried your JavaScript with no success. I added it as a custom calculation script. Nothing happened even when I selected a choice for Sub2 and Sub3.
Please let me know if I am entering it in the wrong place. Thank you.
Copy link to clipboard
Copied
Press Ctrl+J and check if there are any error messages. It should have worked.
Copy link to clipboard
Copied
Here is all of the error message:
ReferenceError: cFields is not defined
7:Field:Validate
ReferenceError: cFields is not defined
7:Field:Calculate
ReferenceError: cFields is not defined
7:Field:Calculate
ReferenceError: cFields is not defined
7:Field:Calculate
ReferenceError: cFields is not defined
7:Field:Mouse Up
ReferenceError: cFields is not defined
7:Field:Mouse Up
ReferenceError: cFields is not defined
7:Field:Calculate
ReferenceError: cFields is not defined
7:Field:Mouse Up
ReferenceError: cFields is not defined
7:Field:Format
ReferenceError: cFields is not defined
7:Field:Mouse Up
ReferenceError: cFields is not defined
7:Field:Format
ReferenceError: cFields is not defined
7:Field:Calculate
ReferenceError: cFields is not defined
7:Field:Format
ReferenceError: cFields is not defined
7:Field:Calculate
SyntaxError: missing ; before statement
31:Field:Calculate
ReferenceError: cFields is not defined
7:Field:Calculate
ReferenceError: cFields is not defined
7:Field:Mouse Up
InvalidSetError: Set not possible, invalid or unknown.
ReferenceError: cFields is not defined
7:Field:Mouse Up
InvalidSetError: Set not possible, invalid or unknown.
ReferenceError: cFields is not defined
7:Field:Calculate
ReferenceError: cFields is not defined
7:Field:Calculate
ReferenceError: cFields is not defined
7:Field:Calculate
ReferenceError: cFields is not defined
7:Field:Calculate
ReferenceError: cFields is not defined
7:Field:Calculate
ReferenceError: cFields is not defined
7:Field:Calculate
ReferenceError: cFields is not defined
7:Field:Calculate
ReferenceError: cFields is not defined
7:Field:Calculate
ReferenceError: cFields is not defined
7:Field:Calculate
ReferenceError: cFields is not defined
7:Field:Calculate
ReferenceError: cFields is not defined
7:Field:Calculate
ReferenceError: cFields is not defined
7:Field:Calculate
ReferenceError: cFields is not defined
7:Field:Calculate
ReferenceError: cFields is not defined
7:Field:Calculate
ReferenceError: cFields is not defined
7:Field:Calculate
ReferenceError: cFields is not defined
7:Document-Level:Group
ReferenceError: nGroup is not defined
1:Field:Calculate
ReferenceError: nGroup is not defined
1:Field:Calculate
ReferenceError: nGroup is not defined
1:Field:Calculate
ReferenceError: nGroup is not defined
1:Field:Calculate
ReferenceError: nGroup is not defined
1:Field:Calculate
ReferenceError: nGroup is not defined
1:Field:Calculate
ReferenceError: nGroup is not defined
1:Field:Calculate
ReferenceError: Group is not defined
1:Field:Calculate
ReferenceError: Group is not defined
1:Field:Calculate
ReferenceError: Group is not defined
1:Field:Calculate
InvalidSetError: Set not possible, invalid or unknown.
InvalidSetError: Set not possible, invalid or unknown.
Copy link to clipboard
Copied
Why are you using the MouseUp event? I told you it needs to be the field's calculation script.
Copy link to clipboard
Copied
I'm sorry, I don't know how I am using the mouseup event. I entered it in Text Field Properties>Calculate tab>Custom calculation script.
I'm sure it's a user error problem. Hopefully your script will help someone else who has the same question but is better with Acrobat Pro.
I do thank you for your help. I'm going to stop trying to figure out what I did wrong as the other script is working and I now have a headache. Which doesn't sound promising for the learning JavaScript book I just downloaded from Amazon. -_-
Copy link to clipboard
Copied
There are some points that need to be clarified.
There maybe some more advanced scripting than just cut and pasting requried.
Copy link to clipboard
Copied
Thank you for your reply.
1. Must all 5 fields be completed? No, it is possible subsite 2 and 3 are not needed.
2. If not how is the missing data to be handled? If the field stays on “Select one” it should be null.
3.Are the combined entries separated by a symbol of some kind? Each selection ends in “-“ also the Object Type contains words like “Calendar_ATM-“ (Symbols used are - and _ )
4. Are the values of any of the drop down fields dependent upon the previous field or fields? No
Copy link to clipboard
Copied
I would use an array variable to gather the values from the fields, filter out the "Select one" items, and then join the elements of the array for the "Group Name" field value;
// Custom calculation for the Group Name;
var aElements = new Array();
var aFields = new Array("Parent", "Sub1", "Sub2", "Sub3", "Type");
for(var i = 0; i < aFields.length; i++)
{
aElements.push(this.getField(aFields).value);
}
function NotSelectOne(value)
{
return value != "Select one";
}
var aCombined = aElements.filter(NotSelectOne)
event.value = aCombined.join("");
Copy link to clipboard
Copied
Thank you for your help. I must be entering it in the wrong place b/c it is not working.
I have tried the Properties>Calculate tab>Custom calculation script
Properties>Validate>Run custom validation script
Properties>Format> tried it under both Custom Format Script and then Custom Keystroke Script.
Verified my naming of fields are the same in script.
Copy link to clipboard
Copied
I don't know what I did last night but I just tested this out again thinking to try the Ctrl + J. It worked!!!
Thank you so much!!!
I appreciate both yours and trv67's help. You guys are great. Thank you again.