Difference between revisions of "Widgets"
m (fix command reference \fillinline, remove link to old source file) |
(moved some elements to enhance structure, added explanations) |
||
Line 1: | Line 1: | ||
< [[Visuals]] | [[Interaction]] > | < [[Visuals]] | [[Interaction]] > | ||
− | You find more about interactive elements in [http://www.pragma-ade.com/general/manuals/mwidget-s.pdf Widgets uncovered]. | + | You can find more about interactive form elements in [http://www.pragma-ade.com/general/manuals/mwidget-s.pdf Widgets uncovered]. It’s written for MkII, but still mostly valid. |
At the moment all of the following examples are from <tt>mwidget</tt> manual. We will cook up our own later. | At the moment all of the following examples are from <tt>mwidget</tt> manual. We will cook up our own later. | ||
− | + | =JavaScript= | |
− | + | If you need to check or otherwise process the input of your forms, you need JavaScript to handle interaction. For simple forms without input validation, you can skip this section. | |
<texcode> | <texcode> | ||
Line 41: | Line 41: | ||
{{Explanation}} | {{Explanation}} | ||
− | + | Relevant commands: | |
− | |||
− | |||
* {{cmd|setupfield}}, {{cmd|setupfields}} | * {{cmd|setupfield}}, {{cmd|setupfields}} | ||
− | * {{cmd|definefield}} | + | * {{cmd|definefield|[name][type][setup name][content values][default content]}} |
− | * {{cmd|field}} | + | * {{cmd|field|[name]}} |
* {{cmd|fillinfield}} | * {{cmd|fillinfield}} | ||
* {{cmd|fillinline}} | * {{cmd|fillinline}} | ||
* {{cmd|fillintext}} | * {{cmd|fillintext}} | ||
* {{cmd|fillinrules}} | * {{cmd|fillinrules}} | ||
+ | |||
+ | Field types: | ||
+ | * line: one line of text | ||
+ | * text: more lines of text | ||
+ | * radio: radiobutton (only one of a group can be active) | ||
+ | * check: checkbox | ||
Beware, for fillinfields in MkIV you need {{code|\usemodule[fields]}}! | Beware, for fillinfields in MkIV you need {{code|\usemodule[fields]}}! | ||
+ | They’re meant for clozes (texts with gaps, like in questionnaires). | ||
+ | |||
+ | Other fields you must first define and then use. That might look complicated, but you can use the same field several times, and the contents will automatically repeat themselves if you need the same content at several places, even on different pages. | ||
+ | |||
+ | ==Text Entries== | ||
<texcode> | <texcode> | ||
\fillinfield[name]{text that defines field length} | \fillinfield[name]{text that defines field length} | ||
− | |||
− | |||
− | |||
</texcode> | </texcode> | ||
− | + | or | |
− | + | <context source=yes> | |
+ | \setupfield[ShortLine][horizontal][width=2cm] | ||
+ | \definefield [Email] [line] [ShortLine] [] [sample@contextgarden.net] | ||
+ | \field [Email] [your email] | ||
+ | </context> | ||
==Radiobuttons== | ==Radiobuttons== | ||
Line 76: | Line 86: | ||
background=screen] | background=screen] | ||
− | \definefield[Logos] [radio] [LogoSetup] | + | \definefield[Logos] [radio] [LogoSetup][ConTeXt,PPCHTEX,TeXUtil] [PPCHTEX] |
− | [ConTeXt,PPCHTEX,TeXUtil] [PPCHTEX] | ||
\definesubfield [ConTeXt] [] [ConTeXtLogo] | \definesubfield [ConTeXt] [] [ConTeXtLogo] |
Revision as of 10:26, 31 March 2015
< Visuals | Interaction >
You can find more about interactive form elements in Widgets uncovered. It’s written for MkII, but still mostly valid.
At the moment all of the following examples are from mwidget manual. We will cook up our own later.
JavaScript
If you need to check or otherwise process the input of your forms, you need JavaScript to handle interaction. For simple forms without input validation, you can skip this section.
\startJSpreamble {name} MyCounter = 0 ; \stopJSpreamble \startJScode {increment} MyCounter = MyCounter + 1 ; // or: ++MyCounter ; \stopJScode \goto {advance by one} [JS(increment)]
You can pass values to a JS function:
\startJScode {increment} MyCounter = MyCounter + JS_V_1 ; \stopJScode \goto {advance by five} [JS(increment{V{5}})]
- V{} is verbose, defaults to string
- S{} = as string
- R{} = as reference
- JS_V_n, JS_S_n, JS_R_n are the names of the variables
- JS_N keeps the number of arguments
Fields
Someone thinks this entry needs some more explanation. | (See: Needs Explanation?, To-Do List.) |
Relevant commands:
- \setupfield, \setupfields
- \definefield[name][type][setup name][content values][default content]
- \field[name]
- \fillinfield
- \fillinline
- \fillintext
- \fillinrules
Field types:
- line: one line of text
- text: more lines of text
- radio: radiobutton (only one of a group can be active)
- check: checkbox
Beware, for fillinfields in MkIV you need \usemodule[fields]
!
They’re meant for clozes (texts with gaps, like in questionnaires).
Other fields you must first define and then use. That might look complicated, but you can use the same field several times, and the contents will automatically repeat themselves if you need the same content at several places, even on different pages.
Text Entries
\fillinfield[name]{text that defines field length}
or
\setupfield[ShortLine][horizontal][width=2cm] \definefield [Email] [line] [ShortLine] [] [sample@contextgarden.net] \field [Email] [your email]
Radiobuttons
Sample from the manual:
\setupfield [LogoSetup] [width=4cm, height=4cm, frame=off, background=screen] \definefield[Logos] [radio] [LogoSetup][ConTeXt,PPCHTEX,TeXUtil] [PPCHTEX] \definesubfield [ConTeXt] [] [ConTeXtLogo] \definesubfield [PPCHTEX] [] [PPCHTEXLogo] \definesubfield [TeXUtil] [] [TeXUtilLogo] \definesymbol [ConTeXtLogo] [{\externalfigure[mpcont.502]}] \definesymbol [PPCHTEXLogo] [{\externalfigure[mpcont.503]}] \definesymbol [TeXUtilLogo] [{\externalfigure[mpcont.504]}] \hbox to \hsize{\hss\field[ConTeXt]\hss\field[PPCHTEX]\hss\field[TeXUtil]\hss}
Checkboxes
\setupfield[setup 3] [width=2cm, height=2cm, rulethickness=3pt, corner=round, framecolor=red] \definesymbol [yes] [{\externalfigure[mpcont.502]}] \definesymbol [no] [] \definefield [checkme][check] [setup 3] [yes,no] [no] \field[checkme]
Tricks
This helps debugging (MkII only!):
\tracefieldstrue \showfields % typeset a table of field relations \logfields % logs field descriptions to a file fields.log