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 sep = frame.args.sep or ','
local optionsTable = mw.text.split( options, sep )
local selected = frame.args.selected or ''
selected = mw.text.trim( selected )
local id = frame.args.id or "randomidhere"
optionElements = {}
for k,v in ipairs( optionsTable ) do
local val = mw.text.trim(v)
local label = val -- for now
if val ~= selected then
local isSelected = true
else
local 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 attributes = {
['value'] = mw.text.trim( val ),
['for'] = id,
['foo`'] = 'bar',
['foo2'] = isSelected
}
if ( isSelected == true ) then
attributes['selected'] = 'selected'
end
local res = frame:extensionTag( 'option', label, attributes );
return res
end
return p
