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):
- 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 {< "<" > ">"} $label]</option>\n}] } append output "</select>" } } } return $outputXQL Not present: PostgreSQL, Oracle Generic XQL file: packages/acs-templating/tcl/widget-procs.xql