template::widget::menu (public)

 template::widget::menu widget_name options_list values_list \
    attribute_reference [ mode ] [ widget_type ]

Defined in packages/acs-templating/tcl/widget-procs.tcl

Render a menu widget (a "select" dropdown menu by default).

Parameters:
widget_name - Name of the widget
options_list - List of option/value pairs (i.e. dropdown menu items)
values_list - List of values (i.e. the selected default value)
attribute_reference - Reference variable to the caller's tag_attributes param
mode (defaults to "edit") - If "edit" the widget is rendered, otherwise values are passed along using hidden input HTML tags
widget_type (defaults to "select") - Select, checkbox, etc
Returns:
Form HTML for widget

Partial Call Graph (max 5 caller/called nodes):
%3 template::widget::ampmFragment template::widget::ampmFragment (public) template::widget::menu template::widget::menu template::widget::ampmFragment->template::widget::menu template::widget::category template::widget::category (public) template::widget::category->template::widget::menu template::widget::comment template::widget::comment (public) template::widget::comment->template::widget::menu template::widget::monthFragment template::widget::monthFragment (public) template::widget::monthFragment->template::widget::menu template::widget::multiselect template::widget::multiselect (public) template::widget::multiselect->template::widget::menu template::util::list_to_lookup template::util::list_to_lookup (public) template::widget::menu->template::util::list_to_lookup template::widget::checkbox template::widget::checkbox (public) template::widget::menu->template::widget::checkbox template::widget::input template::widget::input (public) template::widget::menu->template::widget::input template::widget::radio template::widget::radio (public) template::widget::menu->template::widget::radio template::widget::select template::widget::select (public) template::widget::menu->template::widget::select

Testcases:
No testcase defined.
Source code:

    upvar $attribute_reference attributes

    # Create an array for easier testing of selected values
    template::util::list_to_lookup $values_list values

    set output {}
    if { $mode ne "edit" } {
        set selected_list [list]

        foreach option $options_list {
            lassign $option label value

            if { [info exists values($value)] } {
                lappend selected_list $label
                append output [subst {<input type="hidden" name="$widget_name" value="[ns_quotehtml $value]">}]
            }
        }

        append output [join $selected_list ", "]
    } else {
        switch -exact -- $widget_type {
            checkbox -
            radio {
                if {![info exists attributes(multiple)]} {
                    set widget_type radio
                }
                foreach option $options_list {
                    lassign $option label value

                    append output [subst { <input type="$widget_type" name="$widget_name" value="[ns_quotehtml $value]"}]
                    if { [info exists values($value)] } {
                        append output { checked="checked"}
                    }

                    append output [subst {>[ns_quotehtml $label]<br>\n}]
                }
            }
            default {
                append output [subst {<select name="$widget_name" id="$widget_name" }]

                foreach name [array names attributes] {
                    if {$attributes($name) eq {}} {
                        append output [subst { $name="$name"}]
                    } else {
                        append output [subst { $name="$attributes($name)"}]
                    }
                }
                append output ">\n"

                foreach option $options_list {
                    lassign $option label value

                    append output [subst { <option value="[ns_quotehtml $value]"}]
                    if { [info exists values($value)] } {
                        append output [subst { selected="selected"}]
                    }
                    # The option element contains "normal" character data,
                    # which must not contain any "<". For details, see:
                    # https://www.w3.org/TR/html-markup/syntax.html#normal-character-data
                    append output [subst {>[string map {< "&lt;" > "&gt;"$label]</option>\n}]
                }
                append output "</select>"
            }
        }
    }

    return $output
XQL Not present:
PostgreSQL, Oracle
Generic XQL file:
packages/acs-templating/tcl/widget-procs.xql

[ hide source ] | [ make this the default ]
Show another procedure: