Changes

Jump to navigation Jump to search
1,556 bytes added ,  13:49, 13 June 2017
Radiobutton setup for questionnaire
</texcode>
'''Beware''', in In some versions of MkIV there was a bug that the JS code is was only copied to the PDF if there is was a \goto referencing one of the defined functions!. Should be gone.
You can pass values to a JS function:
<texcode>
\starttext
 
\setupinteraction [state=start]
\startJSpreamble {EXAMPLE} used now
* {{cmd|definefield|[name][type][setup name][content values][default content]}}
* {{cmd|field|[name]}}
* {{cmd|fillinfield}}
* {{cmd|fillinline}}
* {{cmd|fillintext}}
* {{cmd|fillinrules}}
* {{cmd|fillinfield}} (defined in the {{src|m-fields.mkiv|fields}} module, broken)
Field types:
* radio: radiobutton (only one of a group can be active)
* check: checkbox
* signature: electronic signature (since ConTeXt beta of 2016-03-11)
Beware, for fillinfields in MkIV you need {{code|\usemodule[fields]}}!
They’re meant for clozes (texts with gaps, like in questionnaires).
In MkIV (as of 2015-04-01) default values are always used verbatim, i.e. JS() doesn’t work.(Check: other bug is gone, maybe this also?)
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.
</texcode>
orIf you use this command in MkIV, avoid using default validation with <tt>\setupfieldcategory[fillinfield][validate=]</tt>. The default validation removes the contents from field.
<context source=yes>
# setup class (default is inherited, but you can use a different one)
# content symbol, defined by {{cmd|definesymbol}}
 
===Setup for questionnaire===
 
If you need a lot of similar radiobuttons, like in a questionnaire where you answer every question with a range choice, a meta definition makes sense. Fortunately it’s quite easy:
 
<texcode>
\setupfield [ChoiceSetup][width=1em,height=1em,corner=00]
 
\definesymbol[X][X] % replace with dingbat symbol
 
\def\Choice#1{\definefield[#1:main][radio][ChoiceSetup][#1:1,#1:2,#1:3,#1:4,#1:5,#1:0][#1:0]%
\definesubfield [#1:1][][X]%
\definesubfield [#1:2][][X]%
\definesubfield [#1:3][][X]%
\definesubfield [#1:4][][X]%
\definesubfield [#1:5][][X]%
\definesubfield [#1:0][][X]%
\field[#1:1]\,\field[#1:2]\,\field[#1:3]\,\field[#1:4]\,\field[#1:5]\hskip1em\field[#1:0]}
 
\def\ChoiceTitle{\hfill$-$\hskip4em$+$\hskip1.25em?\ \strut\par}
 
\def\Question{\dosingleempty\doQuestion}
% We need the "optional" parameter as reference
\def\doQuestion[#1]#2{%
\iffirstargument
#2\dotfill\Choice{#1}\par
\else
#2\par
\fi
}
 
\starttext
 
\ChoiceTitle
\Question[q:ctx]{How much do you love \CONTEXT?}
\Question[q:lua]{How are your Lua skills?}
\Question[q:xml]{How often do you dream in XML?}
 
\stoptext
</texcode>
==Checkboxes==

Navigation menu