webmcp

diff framework/env/ui/field/file.lua @ 56:36ebcae1cde3

File upload support in env/ui
author jbe
date Sun Dec 18 22:09:58 2011 +0100 (2011-12-18)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/framework/env/ui/field/file.lua	Sun Dec 18 22:09:58 2011 +0100
     1.3 @@ -0,0 +1,24 @@
     1.4 +--[[--
     1.5 +ui.field.file{
     1.6 +  ...                        -- generic ui.field.* arguments, as described for ui.autofield{...}
     1.7 +}
     1.8 +
     1.9 +This function inserts a field for uploading a file in the active slot. For read-only forms this function does nothing. For description of the generic field helper arguments, see help for ui.autofield{...}.
    1.10 +
    1.11 +--]]--
    1.12 +
    1.13 +function ui.field.file(args)
    1.14 +  ui.form_element(args, nil, function(args)
    1.15 +    if args.readonly then
    1.16 +      -- nothing
    1.17 +    else
    1.18 +      if not slot.get_state_table().form_file_upload then
    1.19 +        error('Parameter "file_upload" of ui.form{...} must be set to true to allow file uploads.')
    1.20 +      end
    1.21 +      local attr = table.new(args.attr)
    1.22 +      attr.type  = "file"
    1.23 +      attr.name  = args.html_name
    1.24 +      ui.tag{ tag  = "input", attr = attr }
    1.25 +    end
    1.26 +  end)
    1.27 +end

Impressum / About Us