Geen bewerkingssamenvatting |
Geen bewerkingssamenvatting |
||
| Regel 17: | Regel 17: | ||
]]-- | ]]-- | ||
p.select = function(frame) | p.select = function(frame) | ||
local allValues = frame.args.values or "" --all possible values | local allValues = frame.args.values or "" --all possible values? | ||
local options = frame.args.options or {} | local options = frame.args.options or {} | ||
local sep = frame.args.sep or ',' | local sep = frame.args.sep or ',' | ||
| Regel 23: | Regel 23: | ||
local selected = frame.args.selected or '' | local selected = frame.args.selected or '' | ||
selected = mw.text.trim(selectedVal) | selected = mw.text.trim(selectedVal) | ||
local id = frame.args.id or "randomidhere" | |||
optionElements = {} | |||
for k,v in ipairs( optionsTable ) do | for k,v in ipairs( optionsTable ) do | ||
local | local val = mw.text.trim(v) | ||
if | local label = val -- for now | ||
local isSelected = false | |||
if val ~= selected then | |||
local isSelected = true | |||
end | end | ||
optionElements[k] = p.createSelectOption( val, label, id, isSelected ) | |||
end | end | ||
local res = table.concat( optionElements, "" ) | |||
return res | |||
local res = | |||
return | |||
end | end | ||
Versie van 21 jan 2025 22:12
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(selectedVal)
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
local isSelected = false
if val ~= selected then
local isSelected = true
end
optionElements[k] = p.createSelectOption( val, label, id, isSelected )
end
local res = table.concat( optionElements, "" )
return res
end
--[[
]]--
p.createSelectOption = function( val, label, id, isSelected )
local attribures = {
['value'] = mw.text.trim( val ),
['for'] = id
}
if ( isSelected ) then
attribures['selected'] = 'selected'
end
local input = frame:extensionTag( 'option', label, attributes );
return input
end
return p
