webmcp
view framework/env/ui_deprecated/select.lua @ 205:48ee8826efbe
Correct handling of nil's in return tuples in execute.chunk{...}
| author | jbe | 
|---|---|
| date | Fri Jan 09 21:32:23 2015 +0100 (2015-01-09) | 
| parents | 9fdfb27f8e67 | 
| children | 
 line source
     1 function ui_deprecated.select(args)
     2   local record = assert(slot.get_state_table(), "ui_deprecated.select was not called within a form.").form_record
     3   local value = param.get(args.field) or record[args.field]
     4   local html_options = args.html_options or {}
     5   html_options.name = args.field
     7   ui_deprecated.tag("div", { html_options = { class="ui_field ui_select" }, content = function()
     8     if args.label then
     9       ui_deprecated.tag("div", { html_options = { class="label" }, content = function()
    10         ui_deprecated.text(args.label)
    11       end })
    12     end
    13     ui_deprecated.tag("div", { html_options = { class="value" }, content = function()
    14       ui_deprecated.tag("select", { html_options = html_options, content = function()
    15         if args.include_option then
    16           ui_deprecated.tag("option", { html_options = { value = "" }, content = args.include_option })
    17         end
    18         for i, object in ipairs(args.foreign_records) do
    19           local selected = nil
    20           if tostring(object[args.foreign_id]) == tostring(value) then
    21             selected = "1"
    22           end
    23           ui_deprecated.tag("option", { html_options = { value = object[args.foreign_id], selected = selected }, content = object[args.foreign_name] })
    24         end
    25       end }) -- /select
    26     end }) -- /div
    27   end }) -- /div
    28 end
