RuneScape:Calculators/Form calculators
Form calculators use a script that enables dynamic loading of templates into parts of a page. A configurable form is used to input parameters into the template.
Overview[edit source]
When the form is submitted, the script takes the values from the form and configuration, and constructs a string that is then sent to the wiki servers to be parsed, then the result is received and displayed. The generated wikicode will look like this:
{{template name |param1 = value1 |... |paramN = valueN }}
Or, if the calculator is in module mode:
{{#invoke:module name|module function |param1 = value1 |... |paramN = valueN }}
The generated wikicode will be logged to the console each time the form is submitted. Additional information is logged when in debug mode - add ?debug=1
to the URL and load the page.
Configuration[edit source]
The JS calculator's configuration section uses name = value
pairs, each separated by a newline. The possible names are:
template
- The name of the template to use on form submittal. If no namespace is provided, then the template namespace will be searched by default. If the template is in the main namespace, you must prepend a colon to the article name. This follows the same convention that's used when transcluding templates into a page.module
- The name of the module to invoke on form submittal. This will always be in the Module namespace. Setting this option to anything will override anytemplate
options set.modulefunc
- The name of the function to run within the module. Defaults tomain
. Has no effect without a module name defined.form
- The unique HTML ID of the element that will contain the form. Each configuration block should specify a different form ID.name
- The display name for the calculator. Defaults to Calculator.result
- The unique HTML ID of the element that will contain the parsed template.suggestns
- A comma-separated list of namespace IDs or names to use for autocomplete. This field applies as the default for all article parameter types used in the form, but can be overridden per parameter. By default, namespace 0 (main) is searched. See the table to the bottom for the valid namespace IDs.autosubmit
- Set the autosubmit status off the form, defaults to off, other acceptable values are on or disabled.param
- Defines a parameter to be sent to the template, in the format shown in the next section.
Parameter format[edit source]
A param
line should be in the following format:
param = Param name|Label name|Default value|Param type|Param range|Toggles|Help
Param name
- The name of the parameter as used by the template. Parameter names are case sensitive, and there can be no spaces.Label name
- The label used for the parameter in the form. If blank,Param name
is used.Label name
supports using HTML to format the labels - including simple formats like<em>
,<span>
and even<img />
.Default value
- The default value used to prefill the form initially.Param type
- The type of the parameter, used for form validation and to control the appearance of the form field. For more information on each param type see valid parameter types below. Valid values forParam type
are:string
(default) - The input box can contain any value.group
- Used to group other inputs together.article
- Field for entering the name of an article (page) on the wiki.number
- Field for entering a number.int
- Field for entering an integer.select
- A dropdown list for selecting an option.buttonselect
- A series of buttons for selecting an option (only 1 selected at a time).combobox
- A combination of a select and string input. Users can input any string, and will be prompted with things from the dropdown list that start with the same characters.check
- A checkbox.toggleswitch
- Same function as checkbox but is a toggle instead.togglebutton
- Same function as checkbox but is a button (toggles on/off).hs
- A special field which attempts to lookup a player's hiscores for values to be passed into other parameters.rsn
- A special field for player names (when used by the calculator and not to populate another field).voiceofseren
- A special field that gets filled by the current Voice of Seren from https://api.weirdgloop.org/runescape/vos. Does not generate any output into the form. The label, range, default, toggles, and help are ignored.fixed
- A value that is displayed but cannot be changed by the user.hidden
- A value that is hidden from the user and cannot be changed (no row is created at all).semihidden
- A combination of fixed and hidden: value is hidden from user, and cannot be changed (by the user), however a row is generated such that another script could change it.
Param range
- The allowed range of the parameter. The format of this field depends on theParam type
chosen.Toggles
- The inputs or groups of inputs toggled by this widget. Applies to select, buttonselect, combobox, check, toggleswitch, togglebutton, int and number param types. Toggles are given in the formatvalue=toggles
. Note that when an option is chosen, all the groups/fields listed for other options (that aren't listed on the selected option) will be hidden.- Default toggles: For checkboxes, toggleswitches and togglebutton the keys are "true" and "false" (values specified in
Param range
cannot be used), if no key is given key is assumed to be "true". For number and int inputs available keys are any numbers or "not0" which is also used for any nonzero input (if no key is specified key is assumed to be "non0"). - Value is the name of the option (listed in param range for the input). Multiple options can be assigned them same toggles by separating them with a comma
,
. - Toggles are the groups or fields toggled by that option, multiple groups should be separated by a comma
,
. The group or field names should be those specified in their respecitveparam name
. - Multiple toggle sets are separated by semicolons
;
. - Examples:
- If a select has
Option 1,Option 2
for the range andOption 1=Group1,Group2;Option 2=Group2,Group3
for the toggles then when "Option 1" is selected all inputs that belong to "Group1" and "Group2" will be shown while those belonging to "Group3" will be hidden. when "Option 2" is selected all inputs that belong to "Group2" and "Group3" will be shown while those belonging to "Group1" will be hidden. - If a button select has
Button 1,Button 2,Button 3
for the range andButton 1,Button 2=Input1
for the toggles then when "Button 1" or "Button 2" is selected the other input "Input1" will be displayed while if "Button 3" is selected it will not be.
- If a select has
- Default toggles: For checkboxes, toggleswitches and togglebutton the keys are "true" and "false" (values specified in
Help
- Help text for the form field. If text is Defaults to displaying an (i) icon that can be clicked to display the help.- Default display for help (if given) displays an (i) icon that when clicked shows the help text in a tooltip.
To display the help inline (below the input) start the help withInline is not currently available.inline=
followed by the help text. Help
supports using HTML to format the help (both tooltip and inline) - including simple formats like<em>
,<span>
and even<img />
.
- Default display for help (if given) displays an (i) icon that when clicked shows the help text in a tooltip.
The configuration section should be contained within a <div> or <pre> tag with the class jcConfig
, e.g.:
<pre class="jcConfig"> ... configuration ... </pre>
For example configurations, see /Examples.
Valid Parameter types[edit source]
string
(default) - The input box can contain any value.group
- Used to group inputs together. Items in the group are specified inParam range
as a comma separated list of Param name.Default value
is ignored.
article
- The input box should contain an article name. This field appears similar to the search box, with suggestions provided.- The namespaces used are set using the
Param range
as a comma separated list of namespaces or their ids. Allowable values are the id numbers or names (not case sensitive) of namespaces. Defaults to 0 (main), use all or * for all namespaces. See the table below for a list of valid namespaces and their ids.
- The namespaces used are set using the
number
- The input box must contain a number.- A valid range can be specified in
Param range
in the format min-max,step,buttonstep. If either min or max is omitted or a range is not given, then infinity is assumed, negative numbers can also be given. The step is the step the numbers are allowed in (numbers are valid if they are a multiple of this), defaults to 0.01 (thus allows all numbers too 2 decimal places). The button step is the amount the value increases or decreases when the +/- buttons or arrow keys are pressed, defaults to 1.
- A valid range can be specified in
int
- The input box must contain an integer. A valid range and steps can be specified usingParam range
(see above).select
- The input is selected from a comma-separated list of values given inParam range
.buttonselect
- The input is select of buttons from a comma-separated list of values given inParam range
.combobox
- A combination of a select and string input. Users can input any string, and will be prompted with things from the dropdown list that start with the same characters. Like selects, the contents of the dropdown is defined as a comma-separated list of values given inParam range
.check
- A checkbox, with values sent to the template defined by theParam range
.- The
Param range
has formatvalue if true,value if false
, which defines what the form will pass to the template when ticked or not ticked. The default for this istrue,false
. - The checkbox will be checked by default if the
Default value
is set totrue
or the same as thevalue if true
given in theParam range
.
- The
toggleswitch
- A toggle switch, with values sent to the template defined by theParam range
.- The
Param range
has formatvalue if true,value if false
, which defines what the form will pass to the template when ticked or not ticked. The default for this istrue,false
. - The toggle switch will be on by default if the
Default value
is set totrue
or the same as thevalue if true
given in theParam range
.
- The
togglebutton
- A button, which toggles on/off, with values sent to the template defined by theParam range
.- The
Param range
has formatvalue if true,value if false
, which defines what the form will pass to the template when ticked or not ticked. The default for this istrue,false
. - The toggle button will be selected by default if the
Default value
is set totrue
or the same as thevalue if true
given in theParam range
.
- The
hs
- A special field which attempts to lookup a player's hiscores for values to be passed into other parameters.- The form will automatically try to prefill the form with the last name entered in a
hs
type box. If no name is found thenDefault value
is used. Param range
has a format ofotherparam,skill,value
whereotherparam
is theParam name
of any other parameter in the form,skill
is the integer of the skill to lookup (as defined by the table to the bottom), andvalue
is 0 for rank, 1 for level and 2 for experience (0 for rank and 1 for score in minigames). Multiple parameters can be changed by using;
- i.e.otherparam,skill,value;thirdparam,skill2,value2
.
- The form will automatically try to prefill the form with the last name entered in a
rsn
- A special field for Runescape names, which validates them (based on character inputs).- The form will automatically try to prefill the form with the last name entered in a
hs
type box. If no name is found thenDefault value
is used.
- The form will automatically try to prefill the form with the last name entered in a
fixed
- The value specified byDefault value
will be shown but cannot be changed in the form.hidden
- The value specified byDefault value
will be hidden in the form and cannot be changed. No row is generated for the form at all.semihidden
- A combination of fixed and hidden: The value specified byDefault value
will be hidden in the form and cannot be changed, but unlikehidden
, a row is added to the form, which is hidden with CSS. This is primarily for inter-script usage (i.e. some other script sets the semihidden value to something so that it is passed to the template when submitted).
IDs[edit source]
Namespaces[edit source]
Namespace | Article ID | Talk ID |
---|---|---|
All | * | |
Media | -2 | N/A |
Special | -1 | N/A |
(main) | 0 | 1 |
User | 2 | 3 |
RuneScape | 4 | 5 |
File | 6 | 7 |
MediaWiki | 8 | 9 |
Template | 10 | 11 |
Help | 12 | 13 |
Category | 14 | 15 |
Update | 100 | 101 |
Forum | 110 | 111 |
Exchange | 112 | 113 |
Data | 114 | 115 |
Calculator | 116 | 117 |
Map | 118 | 119 |
Transcript | 120 | 121 |
Property | 302 | 303 |
Map | 118 | 119 |
Module | 828 | 829 |
Beta | 3002 | 3003 |
Hiscores[edit source]
License[edit source]
This script is released under the GNU General Public License. The source code is available at MediaWiki:Gadget-calc-core.js.
Articles | |
Images | |
Advanced | |
Maps | |
Calculators | |
Community |