How do I populate a field when an option menu is changed?
There are lots of situations where we might want to do something when a user selects an option from a menu. As an example this lesson will show you how to populate a field to display some information about what the user has selected. In this case we are displaying information about the different Rev products.
Store the data
First we want to store the data we will use to populate the field. There are a number of ways we could do this, we could read it in from a text file, or have it stored on a different card. In this case I have chosen to store the information in a custom property set. This is an efficient way of storing the data within the stack so there is no need for external files or extra cards or controls.
A custom property set is basically an array. In this case the keys will correspond the the options in the menu and the contents of the array are what we want to display in the field. We will store the array as a custom property set of the card.
Firstly, using the card inspector we create a new custom property set (1), then name it cVersionInformation (2) and save it (3).
Populate with the information
We then add the data to our custom property set. We add a new custom property to represent each option (1) and then put in the information we want to display (2)
Once this is set up we can use array notation to access the data eg.
the cVersionInformation["revEnterprise"] of this card
gives us the information about revEnterprise
Create the interface
Add script to the option menu
As we want to populate the field when an option menu is changed we create a menuPick handler in the script of the option menu. This checks which option has been selected, uses the option as a key to look up the array and populates the field.
on menuPick pItemName
put the cVersionInformation[pItemName] of this card into field "information"
Save current selection
Script the save button
When the save button is clicked we want to update our custom property set with the contents of the field. Again we can use array notation, but this time to store information rather than retrieve it.
local tVersion, tInformation
put the label of button "version" into tVersion
put field "information" into tInformation
set the cVersionInformation[tVersion] of this card to tInformation