Geen bewerkingssamenvatting |
Geen bewerkingssamenvatting |
||
| Regel 103: | Regel 103: | ||
end | end | ||
p.createOptions = function( values, sep, displayprop ) | --[[ | ||
Accept a delimited string of values | |||
and return option inputs as concatenated string | |||
]] | |||
p.createOptions = function( values, sep, displayprop, inputname ) | |||
local valTbl = string.gmatch( values, sep ) | local valTbl = string.gmatch( values, sep ) | ||
local | local str = '' | ||
for val in valTbl do | for k,val in pairs( valTbl ) do | ||
local label = p.smwgetlabel( val, displayprop ) | |||
local inputTbl = { | |||
-- | ['type'] = 'option', | ||
['value'] = val, | |||
['content'] = label, | |||
['for'] = inputname | |||
} | |||
-- render str here | |||
local input = p.inputHandler( inputTbl, 'input' ) | |||
str = str .. input | |||
end | end | ||
return str | |||
end | end | ||
Versie van 4 okt 2023 10:14
Module:FF
invoke within form
{{#invoke:FF|input
|type=text
|name=myname
|value=Value here
|id=fff-443434
|class=form-control
|label=Name
|template=Data item
|slot=
|param=
|template=
}}
Please log in first.
Getdata
Kikkers en tongzoenen - Sarah Mlynowski 2007, 1ᵉ druk, Uitgeverij Van Goor Unieboek BV, Houten:
Titel/-787178247
- Works with parser function though
Titel/-787178247
- getdatatest
Titel/-787178247
local p = {}
p.input = function(frame)
res = p.inputHandler( frame, '_input' )
return res
end
p.textarea = function( frame )
res = p.inputHandler( frame, 'textarea' )
return res
end
p.label = function( frame )
res = p.inputHandler( frame, 'label' )
return res
end
--[[
]]--
p.inputHandler = function( frame, tag )
local tag = tag or "_input"
local content = frame.args.content or frame.args[1] or ""
local content = mw.text.nowiki( content )
local frompage = frame.args.page or ""
local fromslot = frame.args.slot or "main"
local fromtemplate = frame.args.template or "" --template name
local fromparam = frame.args.param or "" --template parameter
local label = frame.args.label or ""
local wrappertemplate = frame.args.wrappertemplate or ""
-- Important! Assign everything from protected frame.args to new table
flexargs = {}
for k,v in pairs( frame.args ) do
flexargs[k] = v
end
-- slot
-- Remove anything from args that should not be sent to FF
local nonffargs = { 'content', 'page', 'slot', 'template', 'param', 'label' }
for name in ipairs( nonffargs ) do
if ( flexargs[name] ~= nil ) then
flexargs[name] = nil
end
end
--add value from slot
if ( frompage ~= "" ) then
slotval = p.getdatafromslot( frompage, fromslot, fromtemplate, fromparam )
if ( flexargs["type"] == 'textarea' ) or ( tag == 'textarea' ) then
content = mw.text.nowiki( slotval )
else
flexargs.value = "" -- likely superfluous
flexargs.value = mw.text.nowiki( slotval )
end
end
-- FF
local forminput = frame:extensionTag( tag, content, flexargs )
-- Should be optional. Usually "Data item"
if ( wrappertemplate == "" ) then
return forminput
else
local res = frame:expandTemplate{ title = wrappertemplate, args = { label, forminput } }
return res
end
end
--[[
FlexForm documentation: https://www.open-csp.org/DevOps:Doc/FlexForm/1.1/token
{{Wstoken SMW
|selected={{{ReeksNr|}}}
|id=tokener-series
|name=ReeksNr[]
|query=,,,
|limit=999
|returnid=
|returntext=Title
|placeholder=
|multiple=
|class=w-100
|allowclear=allowclear
}}
<_token
name="tokenfield[]"
id="tokener"
query="..."
placeholder="Search for Documentation Titles"
multiple="multiple"
allowclear
>
</_token>
]]--
p.token= function(frame)
-- nowiki for query?
local query = frame.args.query or ""
local selected = frame.args.query or ""
-- use createOptions
res = p.inputHandler( frame, '_token' )
return res
end
--[[
Accept a delimited string of values
and return option inputs as concatenated string
]]
p.createOptions = function( values, sep, displayprop, inputname )
local valTbl = string.gmatch( values, sep )
local str = ''
for k,val in pairs( valTbl ) do
local label = p.smwgetlabel( val, displayprop )
local inputTbl = {
['type'] = 'option',
['value'] = val,
['content'] = label,
['for'] = inputname
}
-- render str here
local input = p.inputHandler( inputTbl, 'input' )
str = str .. input
end
return str
end
p.smwgetlabel = function( page, prop )
if not mw.smw then
return "mw.smw module not found"
end
local qarg = "[[" .. page .. "]][[Modification date::+]]" .. "|mainlabel=-" .. "|?" .. prop .. "|link=none"
local q = mw.smw.ask( qarg )
local label = q[0][prop] -- ?
return label
end
--[[
test
]]--
p.getdata = function(frame)
-- todo without pagename, get current page
local page = frame.args.page or mw.title.getCurrentTitle()
local slot = frame.args.slot or "main"
local template = frame.args.template or "" --template name
local param = frame.args.param or nil --template parameter
-- getdatafromslot( page, slot, param )
local str = p.getdatafromslot( page, slot, template, param )
return str
--local pagepropsparams = { slot, page, '@' .. slot }
--local slotdatapf = frame:callParserFunction( '#slottemplates', pagepropsparams )
--local slotdata = frame:preprocess( slotdatapf )
end
--[[
]]--
p.getdatafromslot = function( page, slot, template, param )
local str = "Something went wrong"
--
if ( template == "" ) then
--todo
local str = mw.slots.slotContent( slot, page )
return str
end
--
local slotdata = mw.slots.slotTemplates( slot, page )
local str = slotdata[template][1][param]["_text"]
--local str = slotdata["Book"][1]["TitelNr"]["_text"]
return str
end
-- does not work
p.getdatatest = function()
local slotdata = mw.slots.slotTemplates( "ws-page-props", "Boek/-100102193" )
mw.logObject( slotdata );
local str = slotdata["Book"][1]["TitelNr"]["_text"]
return str
end
--[[
test to show comparison callParserFunction and extensionTag
]]--
p.form1 = function(frame)
-- test of frame:callParserFunction
-- {{#tag:form||id=bla|action=get}}
local content = 'Test'
local formparams = { 'form', content, id = 'bla', action = 'get' }
local str = frame:callParserFunction( '#tag', formparams )
return str
end
--[[
Makes more sense than using callParserFunction
but "equivalent to a call to frame:callParserFunction() with function name '#tag' "
]]--
p.form2 = function(frame)
-- frame:extensionTag( name, content, args )
local content = 'Test'
local tag = 'form'
local args = { id = 'bla', action = 'get' }
local str = frame:extensionTag( tag, content, args )
return str
end
p.printarray = function( mytable )
str = table.concat( mytable, ", " )
return str
end
return p
