You can use input provided by the user in one or more fields in the form to determine the values in a select box. This technique is useful when you want to provide the user with two sets of multiple valid choices from your data source but do not want to enable the user to specify a custom selection. This option thus helps enforce the standardization and validity of users' selections while still typically providing users with multiple options from which to choose.
A common application of this technique occurs on a form with select boxes for both country and state. Using the reportobjid and reportobjvars attributes, you can configure the state select box to display only the states for the country selected by the user.
To use this technique of pre-populating a select box based on a user's selection in an earlier select box, follow this process. This process uses the country-state scenario as a running example.
In our running example, create a report data object to retrieve the list of countries from the database.
When the form appears, the report data object runs and populates the combo box with the resulting data.
Record the ID of the data object for later reference.
Consider the following sample query for a data object for the MDB. This example returns the list of available countries for the service or service option to which the form is attached
SELECT country_id,country_name from my_country_table
This query does the following:
Note: When you use a data object to populate a combo box, do not add any options to the select box, because they are ignored (not used) when the user opens the form. Any options for the select box are ignored, only the data object "matters."
Note: You can optionally localize the tool tip text or the name of the select box if users from different locales use this form.
In our running example, create a second report data object to retrieve the states from the database, based on the country that the user selected. Follow the guidelines in Step 1 to create the second report data object.
select state_id,state_name from my_state_table where country_id=%selected_country%
A valid value is one of the following:
Note: Enclose strings in single quotation marks, as shown. Within a quoted string, if needed, use a backslash (\) as an escape character to specify a literal single quote or apostrophe. For example: $({‘what\’s the status?’})
$({'reportvar':_.user.lastName,’reportvar1’:’abc’,’reportvar2’:12,’reportvar3’:foo()})
In our running example, create a second select box to be populated with the states from the database, based on the country that the user selected. For the reportobjvars attribute of the state select box, specify the pre-defined JavaScript function named ca_fdGetSelectedOptionValues, as follows:
$({'selected_country':ca_fdGetSelectedOptionValues ('<form _id> ','country' )[0]})
Specifies the value of the _id attribute of the form containing the first select box. You reference this form in Step 2.
Specifies the value of the _id attribute of the first select box. You create and record this value in Step 2.
ca_fdFetchSelectData('<form _id>','<field _id>');
Specifies the value of the _id attribute of the form containing the second select box. You reference this form in Step 4.
Specifies the value of _id attribute of the form containing the second select box. You create and record this value in Step 4.
In our running example, set the onchange attribute for the country select box to the following:
ca_fdFetchSelectData('<form _id>','<state field _id>');
As a best practice, test this form with a service in a test environment before you use them in a production environment.
|
Copyright © 2013 CA.
All rights reserved.
|
|