Module:FFSelect
<select name="selectFrut" id="selectme">{{#invoke:FFSelect|select
|options=apple>>>appel;pear>>>peer;banana>>>banaan
|labelled=true
|selected=pear
|sep=;
|id=selectme
}}</select>
local p = {}
--[[
{{#invoke:FFSelect
|selected=pear
|options=apple, pear, banana
|optionlabels=apple--apple; pear--pear; banana--banana
|sep=;
|id=
}}
<select id={id} >
<option for={id} >
</select>
]]--
p.select = function(frame)
--local allValues = frame.args.values or "" --all possible values?
local options = frame.args.options or {}
local labelled = frame.args.labelled or 'false'
if labelled == 'true' then
isLabelled = true
else
isLabelled = false
end
local sep = frame.args.sep or ','
local selected = frame.args.selected or ''
selected = mw.text.trim( selected )
id = frame.args.id or "randomidhere"
local optionsTable = mw.text.split( options, sep )
optionElements = {}
for k,v in ipairs( optionsTable ) do
if isLabelled == true then
-- pair of value and label
local pair = mw.text.split( v, "--" )
local val = mw.text.trim( pair[0] )
local label = pair[1] or val
else
-- no special label
local val = mw.text.trim(v)
local label = val
end
if val == selected then
isSelected = true
else
isSelected = false
end
optionElements[k] = p.createSelectOption( frame, val, label, id, isSelected )
end
local res = table.concat( optionElements, "" )
return res
end
--[[
]]--
p.createSelectOption = function( frame, val, label, id, isSelected )
local attribs = {
value = mw.text.trim(val)
}
attribs["for%s"] = id -- 'for' has special meaning
if ( isSelected == true ) then
attribs['selected'] = 'selected'
end
local res = frame:extensionTag( 'option', label, attribs );
return res
end
return p
