Geen bewerkingssamenvatting |
Geen bewerkingssamenvatting |
||
| Regel 44: | Regel 44: | ||
]]-- | ]]-- | ||
p.createSelectOption = function( frame, val, label, id, isSelected ) | p.createSelectOption = function( frame, val, label, id, isSelected ) | ||
local | local attribs = { | ||
['value'] = mw.text.trim( val ), | ['value'] = mw.text.trim( val ), | ||
['for'] = id | ['for'] = id | ||
} | } | ||
if ( isSelected == true ) then | if ( isSelected == true ) then | ||
attribs['selected'] = 'selected' | |||
end | end | ||
local res = frame:extensionTag( 'option', label | local res = frame:extensionTag( 'option', label, attribs ); | ||
return res | return res | ||
end | end | ||
return p | return p | ||
Versie van 21 jan 2025 22:34
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 )
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
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 ),
['for'] = id
}
if ( isSelected == true ) then
attribs['selected'] = 'selected'
end
local res = frame:extensionTag( 'option', label, attribs );
return res
end
return p
