ad_db_select_widget

one of the documented procedures in this installation of the ACS
Usage:
ad_db_select_widget { -size 0 -multiple 0 -default {} -option_list {} -blank_if_no_db 0 -hidden_if_one_db 0 } db sql name
What it does:
given a db handle and sql this generates a select group. If there is only one value it returns the text and a hidden variable setting that value. The first selected column should contain the optionlist items. The second selected column should contain the optionlist values.

option_list is a list in the same format (i.e. {{str val} {str2 val2}...}) which is prepended to the list

if db is null then the list is constructed from option_list only.

if there is only one item the select is not generated and the value is passed in hidden form variable.

if -multiple is given the a multi select is returned.

if -blank_if_no_db set then do not return a select widget unless there are rows from the database

Defined in: /web/philip/packages/acs-core/widgets-procs.tcl

Source code:

arg_parser_for_ad_db_select_widget $args
 
    set retval {}
    set count 0
    set dbcount 0
    if {![empty_string_p $option_list]} {
        foreach opt $option_list { 
            incr count
            set item [lindex $opt 1]
            set value [lindex $opt 0]
            if { (!$multiple && [string compare $value $default] == 0) 
                 || ($multiple && [lsearch -exact $default $value] > -1)} {
                append retval "<option SELECTED value=\"$value\">$item\n"
            } else {
                append retval "<option value=\"$value\">$item\n"
            }
        }
    }

    if { $blank_if_no_db} {
        set count 0
    }

    if {! [empty_string_p $db]} {
        set selection [ns_db select $db $sql]
        while { [ns_db getrow $db $selection] } {
            incr count
            incr dbcount
            set item [ns_set value $selection 0]
            set value [ns_set value $selection 1]
            if { (!$multiple && [string compare $value $default] == 0) 
                 || ($multiple && [lsearch -exact $default $value] > -1)} {
                append retval "<option SELECTED value=\"$value\">$item\n"
            } else {
                append retval "<option value=\"$value\">$item\n"
            }
        }
    }
    
    if { $count == 0 } { 
        if {![empty_string_p $default]} { 
            return "<input type=hidden value=\"[philg_quote_double_quotes $default]\" name=$name>\n"
        } else { 
            return {}            
        }
    } elseif { $count == 1 || ($dbcount == 1 && $hidden_if_one_db) } {
        return "$item<input type=hidden value=\"[philg_quote_double_quotes $value]\" name=$name>\n"
    } else { 
        set select "<select name=$name"
        if {$size != 0} { 
            append select " size=$size"
        } 
        if {$multiple} {
            append select " multiple"
        }
        return "$select>\n$retval</select>"
    }


philg@mit.edu