How to create a read-only dropdown list

Tony Marston - 23rd September 2000

If you have a dropdown list in a maintenance form which allows the user to browse through the list of options in order to pick the one that is wanted, how can you show the current setting in a read-only form?

1. Change the field syntax to 'NED'
This is the easiest method, but it has the disadvantage that when the field has focus the list becomes visible. It is only when the user clicks on an entry which is different from the current one that error message '0104 - field is display only' is displayed.
2. Create a separate non-database field
This should have the widget type of 'EditBox' instead of 'DropDownList', but it requires additional code in order to extract the correct representation from the valrep list. This could look something like the following:
getitem/id display_field, $valrep(ddl_field), ddl_field
3. Create a custom widget
This enables you to continue using the original field, but as well as changing the field syntax to 'NED' you change the widget type to something like 'DropNoEdit' which is defined in your .ini file as follows:
DropNoEdit=udropdownlist(3d=off;entries=0;forcefit=on;dynamic=on;autoselect=off)

These settings prevent anything other than the current value from being displayed, therefore the user is not tempted to change it. As this is more effective than option (1) and requires less effort than option (2) it is my personal favourite.


Tony Marston
23rd September 2000

mailto:tony@marston-home.demon.co.uk
mailto:TonyMarston@hotmail.com
http://www.tonymarston.net

counter