Extension:VisualData/Forms

From mediawiki.org

Forms[edit]

VisualData's forms are automatically generated by the extension on the basis of the json-schema(s) created through the SchemaBuilder and they can be rendered on the page either using the parser function visualdataform or through the template "VisualDataForm" completed with TemplateData for an easy use through Extension:VisualEditor.

Technically (or at design level) a form is an envelope for one or more schemas (a form can contain multiple schemas, and they will be displayed using OOUI tab panels or BookletLayouts) determining the data to be edited, the target page, and additional options related to wiki articles like freetext, categories and so on.


(insert template button from the VisualEditor menu)



(list of available templates bundled with VisualData)


Alternatively a form can be added to an article using the following parser function:

{{#visualdataform: Book
|title = Book
|action = create
|edit-page = 
|return-page = 
|view = popup
|popup-size = medium
|css-class =
|pagename-formula =
|edit-freetext = true   
|edit-categories = false
|edit-content-model = false
|edit-target-slot = false
|target-slot = jsondata
|default-categories = 
|default-content-model = wikitext
|preload=
|preload-data=
|layout-align = top
|popup-help = false 
|layout = tabs
|submit-button-text =
|validate-button-text =
}}


This is an example of a popup form containing a schema created using the SchemaBuilder and rendered on the wikipage using the previous parser function.


A VisualData' form can have either one or two states, or steps: validate, submit, or validate & submit. A form has 2 states when it also allows to edit the article's freetext, categories, and/or content model, so that in the first step the user fills the schema(s) data and in the second step the article-related data.

In both cases the form is validated through ajv-validator, on the basis of the provided schema(s) and error messages are displayed directly on the form. This way the entered data are guaranteed to comply with the schema definition, that in turn allows a wide variety of settings related to validation, like minimum and maximum items for lists (arrays), validation patterns using regex and of course required fields.



(example of validation error using a validate pattern)


Available parameters[edit]

Here are the available parameters for the visualdataform parser function and their default values.


parameter description default
(unnamed parameter) one more schema name, comma separated (user defined)
action form action, can be create or edit create
edit-page title of the page holding the data to edit (with edit action)
return-page return page with action edit the form will return on the page holding the form, with action create the form will return to the target page
title title of the form (or the panel if a form containing multiple schemas) (the schema name)
view display mode of the form, can be inline or popup inline
popup-size popup-size, possible values: small, medium, large, larger full medium
css-class css-class to be attached to the form VisualDataForm
pagename-formula formula used to create a new article through the form with the entered data, in the form contacts/<first_name> <last_name>, where "first_name" and "last_name" are the property names of the related schema
edit-freetext whether the form allows to edit freetext false
edit-categories whether the form allows to edit categories false
edit-content-model whether the form allows to edit the content model false
edit-target-slot whether the form allows to edit the target slot false
target-slot target slot for the semantic data, could be jsondata or main jsondata
default-categories default categories (comma separated)
default-content-model default content model wikitext
preload preload freetext content
preload-data preload json-data
preload-data?[json pointer] overrides specific properties / property paths of json data (the json pointer must contain the schema name if multiple schemas are included in form)
layout-align default align for the OO.ui.FieldLayout, possible values are left right top inline top
popup-help corresponds to helpinline set to false in the OO.ui.FieldLayout false
submit-button-text text of the submit button Submit
validate-button-text text of the validate button Validate
layout form layout with multiple schemas, can be tabs or booklet tabs



Example of a VisualData's form with various available inputs and content-block with an image rendered using wikitext:


See also[edit]