Documentation for modules

Attention! This module is copied from Wikipedia:Module:Form, do not modify it! To ensure Appropedia's long-term sustainability, all modules (except Module:Appropedia) are copied from Wikipedia and should only be edited to keep them up to date with the latest version.

See Wikipedia:Module:Form for this module's documentation.

See also

-- Module:Form implements Template:Form
-- Documentation and master version: https://www.mediawiki.org/wiki/Module:Form
-- Author: User:Sophivorus
-- License: CC-BY-SA-4.0

local Form = {}

function Form.main( frame )
	local args = frame.args
	for key, value in pairs( frame:getParent().args ) do
		args[ key ] = value -- Let page-level args override template-level args
	end

	-- Make the form div
	local noscript = args[ 'noscript' ] or 'Loading...'
	local form = mw.html.create( 'div' ):addClass( 'template-form' ):wikitext( noscript )

	-- Add the form attributes
	form:attr( 'id', args[ 'id' ] )
	form:attr( 'style', args[ 'style' ] )
	form:addClass( args[ 'class' ] )

	-- Add the attributes that control the general behavior of the form
	form:attr( 'data-template', args[ 'template' ] )
	form:attr( 'data-page', args[ 'page' ] )
	form:attr( 'data-section', args[ 'section' ] )
	form:attr( 'data-redirect', args[ 'redirect' ] )
	form:attr( 'data-group', args[ 'group' ] )

	-- Add the field attributes
	for n = 0, 99 do
		local name = args[ 'field' .. n ]
		if ( name ) then
			form:attr( 'data-field' .. n, args[ 'field' .. n ] )
			form:attr( 'data-field' .. n .. '-label', args[ 'field' .. n .. '-label' ] )
			form:attr( 'data-field' .. n .. '-help', args[ 'field' .. n .. '-help' ] )
			form:attr( 'data-field' .. n .. '-type', args[ 'field' .. n .. '-type' ] )
			form:attr( 'data-field' .. n .. '-value', args[ 'field' .. n .. '-value' ] )
			form:attr( 'data-field' .. n .. '-placeholder', args[ 'field' .. n .. '-placeholder' ] )
			form:attr( 'data-field' .. n .. '-required', args[ 'field' .. n .. '-required' ] )
			form:attr( 'data-field' .. n .. '-disabled', args[ 'field' .. n .. '-disabled' ] )
			form:attr( 'data-field' .. n .. '-values', args[ 'field' .. n .. '-values' ] )
			form:attr( 'data-field' .. n .. '-values-from-search', args[ 'field' .. n .. '-values-from-search' ] )
			form:attr( 'data-field' .. n .. '-values-from-property', args[ 'field' .. n .. '-values-from-property' ] )
			form:attr( 'data-field' .. n .. '-values-from-service', args[ 'field' .. n .. '-values-from-service' ] )
			form:attr( 'data-field' .. n .. '-min', args[ 'field' .. n .. '-min' ] )
			form:attr( 'data-field' .. n .. '-max', args[ 'field' .. n .. '-max' ] )
			form:attr( 'data-field' .. n .. '-selected', args[ 'field' .. n .. '-selected' ] )
		end
	end

	-- Add the attributes that control the form messages
	form:attr( 'data-submit', args[ 'submit' ] )
	form:attr( 'data-submit-success', args[ 'submit-success' ] )
	form:attr( 'data-submit-error', args[ 'submit-error' ] )
	form:attr( 'data-template-error', args[ 'template-error' ] )
	form:attr( 'data-namespace-error', args[ 'namespace-error' ] )
	form:attr( 'data-group-error', args[ 'group-error' ] )

	return form
end

return Form
Cookies help us deliver our services. By using our services, you agree to our use of cookies.