Search these areas:
Support Forums
Product Info

-DataWeb: What's New
-Creating an Application
-The DataWeb Designer
-Application Management
-Data Tables
-Data Tables
-Data Analysis
-Object Model
-Full-Text Search
-Domain and Email Hosting
-HotBlock Modules
-Account Management
-New Responsive UI Module

DataWeb Help
Support Forums
Script Library
Knowledge Base

Home > Support

Support Forum

Explicit use of lookup tables
gravy asked:
In an insert view, I have a field in which the user enters a country code, and another (read-only) field which displays the corresponding country, from a lookup table.

What is the easiest way to implement this?

Ali G.
  edl responded:
  There are two easy ways to do this, and both involve creating a special TYPE of field called a "lookup".  As it sounds, this field type looks-up data from another table.

Here are the two ways to create lookup tables:

-create a new field
-choose the type 'Text'
-click the options button 
-this will bring up a window where you can type in the list of possible values.

When you submit this list, it will automatically store these items as a new table under a folder called "lookups".  When you access this field in insert or update mode, it will give you a drop down list of these values.

-create a second table to store your country names (in this example, call it "Country")
-return to your original view
-add a new field
-When you select the type, you will see that "Lookup_Country" is now an option.

As above, this will give you a drop down list.

(Note that once you establish this lookup between tables, you can use it later to display other fields from the Country table.)
  matthewb responded:
  Is there an explicit reason you need to have user type the country code, rather than pick from a dropdown list?  
  gravy responded:
  Thanks matthew,
I have on occasion created the normal lookup tables, especially when the choices (showing up in the drop down) are limited.

The reasons for having the user type the code was that there are around 600 codes, so scrolling would be a hassle (and I'd have to sort it based on country instead of the code)
  dougl responded:
  I can help you write some custom view-source XML to do this.

Your example: a text-input field + a list of all options displayed in read-only mode is fairly simple.

Would you rather have a list of countries + country-codes with radio buttons next to each country? With this style interface, you don't have to write script to ensure your users input valid data.
  matthewb responded:
  I can think of three general ways to solve this problem.  I'm guessing that for your purposes solution 1 is appropriate, but I'll describe them all because they may come in handy.

1) Use the drop down on the form, but associate an unbound input box with it.  In the onchange event handler for the input box, do a lookup in the options collection of the select and set the selectedIndex to the appropriate options.

This will allow the user to drop down the select if they don't know the country code, but will also allow quick data entry if they do.

Variations on this would hide the "lookup" information in an array rather than a visible select object.

2) Build a custom "picker".  Add a button/image next to the bound input (putting this in the caption works pretty well.  This button brings up a separate view file that lets the user pick a value from a list (e.g. a grid).  This view has code to push the selected value into the appropriate input in the parent window.

This can work really well when choosing from lists that are too long for a drop down.

3) Do the lookup in the background.  Without the gory details, you can talk to the server in the background using a hidden frame to get information (e.g. country name) and poke the information into your form.  Way overkill for this case, but it can be handy when building complicated UI.

The code for solution 1 should be pretty easy to figure out, but let us know if you need pointers.
  dougl responded:
  DataWeb considers this issue closed.
If you have additional questions or comments about this issue, please open it again.
If you have questions about a different topic please open a new support question.

DataWeb Support
  Please Log On
or create your own DataWeb Account.
Affiliate | Partner | Terms of Use | Privacy Policy | Contact Us | Pricing | Bring DataWeb In-House    
DataWeb, 720 North 10th Street, A #145, Renton, Washington 98057 *425-583-5970* Fax 484-770-4706* Email Us