Highlighted

Multiple Combo boxes using the same set of predetermined data.

New Here ,
Aug 25, 2020

Copy link to clipboard

Copied

My expertise in Java is -1, so complete newbie here. 

I turned to this common link to learn about combo boxes: https://acrobatusers.com/tutorials/change_another_field/ and am slowly getting this to work on its own.  Now my question, is it possible, using this code from the above link: 


// Place all prepopulation data into a single data structure

var DeptData = { Accounting:{ contact: "Steala Damuni",

                              email: "accounting@mycomp.com",

                              deptnum: "cmp1234" },

                 Engineering:{ contact: "Frank N. Stien",

                              email: "engineering@mycomp.com",

                              deptnum: "eng1234" },

                 Marketing :{ contact: "Shelly Oughtbuks",

                              email: "marketing@mycomp.com",

                              deptnum: "mkt1234" },

                 ITSupport:{ contact: "Goah  Wei",

                              email: "it@mycomp.com",

                              deptnum: "its1234" }};

function SetFieldValues(cDeptName)

{

  this.getField("DeptContact").value = DeptData[cDeptName].contact;

  this.getField("DeptEmail").value = DeptData[cDeptName].email;

  this.getField("DeptNumber").value = DeptData[cDeptName].deptnum;

}

And repeat it within the same JavaScript? I figured out how to set the combo box to give me the values I want, but not to a separate combo box giving me different values. Example:

Combobox A (DeptData) is given a selection and autopopulates gives me output for Engineering
Combobox B (DeptData1) pulls from the same group of prefilled options and gives me output for Accounting.

Using two combo boxes, I can get two sets of data. I hope I'm making sense.

Otherwise, I'm making 150+ scripts, one for each possible selection with the same group of outputs.

Thank you,
Lahrs

TOPICS
Acrobat SDK and JavaScript, How to

Views

97

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Multiple Combo boxes using the same set of predetermined data.

New Here ,
Aug 25, 2020

Copy link to clipboard

Copied

My expertise in Java is -1, so complete newbie here. 

I turned to this common link to learn about combo boxes: https://acrobatusers.com/tutorials/change_another_field/ and am slowly getting this to work on its own.  Now my question, is it possible, using this code from the above link: 


// Place all prepopulation data into a single data structure

var DeptData = { Accounting:{ contact: "Steala Damuni",

                              email: "accounting@mycomp.com",

                              deptnum: "cmp1234" },

                 Engineering:{ contact: "Frank N. Stien",

                              email: "engineering@mycomp.com",

                              deptnum: "eng1234" },

                 Marketing :{ contact: "Shelly Oughtbuks",

                              email: "marketing@mycomp.com",

                              deptnum: "mkt1234" },

                 ITSupport:{ contact: "Goah  Wei",

                              email: "it@mycomp.com",

                              deptnum: "its1234" }};

function SetFieldValues(cDeptName)

{

  this.getField("DeptContact").value = DeptData[cDeptName].contact;

  this.getField("DeptEmail").value = DeptData[cDeptName].email;

  this.getField("DeptNumber").value = DeptData[cDeptName].deptnum;

}

And repeat it within the same JavaScript? I figured out how to set the combo box to give me the values I want, but not to a separate combo box giving me different values. Example:

Combobox A (DeptData) is given a selection and autopopulates gives me output for Engineering
Combobox B (DeptData1) pulls from the same group of prefilled options and gives me output for Accounting.

Using two combo boxes, I can get two sets of data. I hope I'm making sense.

Otherwise, I'm making 150+ scripts, one for each possible selection with the same group of outputs.

Thank you,
Lahrs

TOPICS
Acrobat SDK and JavaScript, How to

Views

98

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 25, 2020 0
Most Valuable Participant ,
Aug 26, 2020

Copy link to clipboard

Copied

Yes, it sure is. You can either do it by supplying the names of the fields as parameters to the SetFieldValues function, or by duplicating it and renaming it for each set of fields. The former is a better option, of course, as its more generic. The code would then need to be placed as a doc-level script, and you just call it from each field's Validation or Format event with the correct function name or parameters.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 26, 2020 1
New Here ,
Aug 26, 2020

Copy link to clipboard

Copied

I'm being dense and not getting it. Like I said, I'm brand new to this and trying tutorials. I've finished the combo box one above, but need to have duplicate with different results:
Clipboard01.jpg
All I've done is copy and pasted the fields and then renamed then added a 1 in the second field names. Otherwise they would just show up identical no matter what I did.

// Place all prepopulation data into a single data structure
var DeptData = { Accounting:{ contact: "Steala Damuni",
                              email: "accounting@mycomp.com",
                              deptnum: "cmp1234" },
                 Engineering:{ contact: "Frank N. Stien",
                              email: "engineering@mycomp.com",
                              deptnum: "eng1234" },
                 Marketing :{ contact: "Shelly Oughtbuks",
                              email: "marketing@mycomp.com",
                              deptnum: "mkt1234" },
                 ITSupport:{ contact: "Goah  Wei",
                              email: "it@mycomp.com",
                              deptnum: "its1234" }};
function SetFieldValues(cDeptName)
{
  this.getField("DeptContact").value = DeptData[cDeptName].contact;
  this.getField("DeptEmail").value = DeptData[cDeptName].email;
  this.getField("DeptNumber").value = DeptData[cDeptName].deptnum;
}
// Place all prepopulation data into a single data structure
var DeptData1 = { Accounting:{ contact: "Steala Damuni",
                              email: "accounting@mycomp.com",
                              deptnum: "cmp1234" },
                 Engineering:{ contact: "Frank N. Stien",
                              email: "engineering@mycomp.com",
                              deptnum: "eng1234" },
                 Marketing :{ contact: "Shelly Oughtbuks",
                              email: "marketing@mycomp.com",
                              deptnum: "mkt1234" },
                 ITSupport:{ contact: "Goah  Wei",
                              email: "it@mycomp.com",
                              deptnum: "its1234" }};
function SetFieldValues(aDeptName)
{
  this.getField("DeptContact1").value = DeptData1[aDeptName].contact;
  this.getField("DeptEmail1").value = DeptData1[aDeptName].email;
  this.getField("DeptNumber1").value = DeptData1[aDeptName].deptnum;
}

I then did the same with the DeptData1 and the getField("DeptContact1") and so forth. Now all that happens is the left and right combo box controls just the right data boxes. I wish I was able to take a javascript class but there are none where I live, so it is just books, demos and asking questions here.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 26, 2020 0
Most Valuable Participant ,
Aug 26, 2020

Copy link to clipboard

Copied

- Do not duplicate the data model. The entire point of doing it is to have only one source of the data.

- Each function needs to have a unique name. Rename the second function to SetFieldValues1, for example, and then call it from your second field, instead of SetFieldValues, which should be called from the first one.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 26, 2020 0
New Here ,
Aug 26, 2020

Copy link to clipboard

Copied

// Place all prepopulation data into a single data structure
var DeptData = {
    Accounting: {
        contact: "Steala Damuni",
        email: "accounting@mycomp.com",
        deptnum: "cmp1234",
        degree: "Education",
        experience: "Very little"
    },
    Engineering: {
        contact: "Frank N. Stien",
        email: "engineering@mycomp.com",
        deptnum: "eng1234"
    },
    Marketing: {
        contact: "Shelly Oughtbuks",
        email: "marketing@mycomp.com",
        deptnum: "mkt1234"
    },
    ITSupport: {
        contact: "Goah  Wei",
        email: "it@mycomp.com",
        deptnum: "its1234"
    }
};

function SetFieldValues(cDeptName) {
    this.getField("DeptContact").value = DeptData[cDeptName].contact;
    this.getField("DeptEmail").value = DeptData[cDeptName].email;
    this.getField("DeptNumber").value = DeptData[cDeptName].deptnum;
    this.getField("Degree").value = DeptData[cDeptName].degree;
    this.getField("Experience").value = DeptData[cDeptName].experience;

}

function SetFieldValues1(cDeptName) {
    this.getField("DeptContact1").value = DeptData[cDeptName].contact;
    this.getField("DeptEmail1").value = DeptData[cDeptName].email;
    this.getField("DeptNumber1").value = DeptData[cDeptName].deptnum;
    this.getField("Degree1").value = DeptData[cDeptName].degree;
    this.getField("Experience1").value = DeptData[cDeptName].experience;

}

No matter what I try, the left columns work just fine, only working the left ("DeptContact") and the others. The right combo box will only control the left side. It seems to completely ignore that the combo box is DepartmentNames1 and the this.getField("DeptContact1") and the others.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 26, 2020 0
Engaged ,
Aug 26, 2020

Copy link to clipboard

Copied

Add "1" like this:

var DeptData1 = { Accounting:{ contact: "Steala Damuni",
email: "accounting@mycomp.com",
deptnum: "cmp1234" },
Engineering:{ contact: "Frank N. Stien",
email: "engineering@mycomp.com",
deptnum: "eng1234" },
Marketing :{ contact: "Shelly Oughtbuks",
email: "marketing@mycomp.com",
deptnum: "mkt1234" },
ITSupport:{ contact: "Goah Wei",
email: "it@mycomp.com",
deptnum: "its1234" }};
function SetFieldValues1(cDeptName1)
{
this.getField("DeptContact").value = DeptData1[cDeptName1].contact;
this.getField("DeptEmail").value = DeptData1[cDeptName1].email;
this.getField("DeptNumber").value = DeptData1[cDeptName1].deptnum;
}

 

In second combobox also set "SetFieldValues1"

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 26, 2020 0
Most Valuable Participant ,
Aug 26, 2020

Copy link to clipboard

Copied

This code seems fine. I'll need to see your actual file to be able to help you further. Can you share it?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 26, 2020 0
New Here ,
Aug 26, 2020

Copy link to clipboard

Copied

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 26, 2020 0
Most Valuable Participant ,
Aug 26, 2020

Copy link to clipboard

Copied

Update the code under DepartmentNames1 to:

 

if( event.willCommit )
{
   if(event.value == " ")
     this.resetForm(["DeptContact1","DeptEmail1","DeptNumber1"]);
   else
     SetFieldValues1(event.value);
}






 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 26, 2020 1
Lahrs LATEST
New Here ,
Aug 26, 2020

Copy link to clipboard

Copied

That was it! Thank you.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 26, 2020 0