Page 2 of 2

Re: Convert a Menu to a dropdown box?

Posted: Wed Feb 04, 2015 4:16 pm
by Scott Klement
Most of this stuff isn't specific to Profound UI. For the stuff that is, however, you can find it documented here:
http://www.profoundlogic.com/docs/displ ... ipt+Coding

Using the stuff I posted as an example:

Code: Select all

1: var choices = ["-- Select --"];
2: var values = ["-"];
3: for (var row=2; row<=11; row++) {
4:  var elem = "D_" + row + "_7";
5:  var resp = "I_" + row + "_5";
6:  choices.push(get(elem));
7:  values.push(resp);
8:  hideElements(elem, resp);
} 
 9:applyProperty("myDropdown", "choices", JSON.stringify(choices));
10:applyProperty("myDropdown", "choice values", JSON.stringify(values));
Genie names it's elements based on the data type (I=Input field, D=Display-only field) and the row/column. So D_2_7 would be a display field in row 2, column 7. I_4_5 is an input field in row 4, column 5, etc. So we wanted to loop through and find/hide the fields that were I_row_5, and D_row_7 for rows 2-11.

Lines 1 & 2 in the code above are normal JavaScript declarations for an array. They put "-- Select --" as the first array element for the choices, and "-" as the first array element for the values. So nothing profound-specific here.

Line 3 is a normal JavaScript for loop. Loops from 2-11.. nothing profound-specific.

Lines 4 & 5 are just building strings to identify the fields we want. So normal string concatenation to build the ID in the format specific to Genie.

Line 6 calls the Profound get() API to retrieve the value of the display field. It then pushes it onto the end of the array. 'push' is standard JavaScript, but the get() call is Profound-specific, and documented here: http://www.profoundlogic.com/docs/displ ... %28+id+%29

Line 7 is standard JS, just pushes a string onto the array.

line 8 is a Profound-specific API to hide elements on the screen. We pass the two IDs (I_row_5 and D_row_7) into it, and it will hide them. This is documented here: http://www.profoundlogic.com/docs/displ ... etc...+%29

lines 9 & 10 use the applyProperty() API, which is a Profound-specific API to change a property of a widget programmatically. They convert the arrays into JSON text using the standard JavaScript JSON.stringify() routine, and then apply this as the 'choices' or 'choice values' properties of the dropdown (just like you can do by hand if you go into the widget properties in the designer.) The applyProperty() API can be found here: http://www.profoundlogic.com/docs/displ ... opValue%29

Here's the other piece of code:

Code: Select all

1: var resp = get(this);
2: if (resp != "-") {
3:   changeElementValue(resp, "1");
4:   pressKey("Enter");
}
Line 1: Again, uses the get() API. Since this is running from the dropdown's onchange event, the 'this' variable refers to the dropdown, so I don't have to hard-code the name of the dropdown, I can just do get(this) to get it's value.

Line 2: standard Javascript 'if' statement. If the user selected the choice in the dropdown that said "--Select--" the value will be "-", so they haven't selected anything and therefore we shouldn't do anything if the value is "-".

Line 3: changeElementValue() is a profound-specific API to change the value of a widget. In this case, putting a "1" into the underlying green-screen input field (I_row_5) that was hidden earlier. changeElementValue() is documented here: http://www.profoundlogic.com/docs/displ ... +value+%29

Line 4: pressKey() is a genie-specific API that acts like the user pressed one of the 5250 keys that submit a screen (Enter, PageUp/PageDown, F-keys, etc). In this case, pressing Enter to submit the screen. pressKey() is documented here: http://www.profoundlogic.com/docs/displ ... 28+key+%29

Does that help?

Re: Convert a Menu to a dropdown box?

Posted: Wed Feb 04, 2015 4:49 pm
by rmarsh
That is awesome. You're the best Scott.

I am still a greenhorn in regards to Javascript so I am (aside from stumbling around in Genie and asking for help with stuff I screwed up) doing some basic Javascript training by going through some tutorials that I have found.