Skip to content

Forms

Use form controls when the player sets a flag, picks one of a few options, drags a value or chooses from a list, and a view model must see the choice.

The FormControls sample has a checkbox, a radio group, a range and a select. Each shows a model value and writes every change back to it; a readout under them shows what the view model holds. Most form markup and CSS from a web page works; see the limits below. Run the sample by choosing FormControls in the samples list in the map L_ArcRmlSamples (Samples). Text fields have their own page: Text fields.

The FormControls sample: a Subtitles checkbox, a Warrior, Mage, Rogue radio group, a volume range, a quality select and the readout line

Show and write back

:checked, :value and attr:value set the control from the model. :checked and :value also write the control's change back to the field: no function and no event handler. Every field Blueprint may write is two-way; a view model needs only the field:

FormControls/ArcRmlSamplesFormControls.h
UPROPERTY(BlueprintReadWrite, FieldNotify, Category = "Samples")
bool bSubtitles = true;
  • A field that is BlueprintReadOnly (or not Blueprint-visible) is refused: the write logs an error naming the field, and the validator warns read-only-field. Make the field BlueprintReadWrite, or send the change with on:input or on:change and call() a function that sets it (Text fields does).
  • The write reaches the game in order with call()s. The game then answers with the stored value, so a value it clamps or refuses comes back to the control.
  • In an editor preview, or with no local player, the write logs [preview] write and the value stays in the UI only.
  • A value written by a binding fires no event. Limits: Limits.

Checkbox

FormControls.rml
<input id="fc-subtitles" type="checkbox" autofocus=""
    :checked="fc.bSubtitles"/>
<label for="fc-subtitles">Subtitles</label>
  • :checked with a bool checks the box when the bool is true.
  • A toggle by click, Space, Enter, gamepad accept or a click on its <label> fires input, then change. ev.checked is the box's state after the toggle.
  • ev.value of a checkbox or radio is its value attribute (on without one), checked or not. Use ev.checked for the state.

Bind a checkbox with :checked

attr:checked="Flag" writes the bool as text, so a false value sets checked="0". Any checked attribute checks the control, so the box stays checked. :checked="Flag" (a bool, or a string equal to the control's value) and attrif:checked="Flag" (the attribute is set when true and removed when false) check and uncheck correctly.

Radio group

FormControls.rml
<input id="fc-warrior" type="radio" name="class" value="warrior"
    :checked="fc.ClassName"/> Warrior
<input id="fc-mage" type="radio" name="class" value="mage"
    :checked="fc.ClassName"/> Mage
<input id="fc-rogue" type="radio" name="class" value="rogue"
    :checked="fc.ClassName"/> Rogue
  • Radios with the same name are one group: checking one unchecks the others. A group is the radios inside the same <form>; radios outside every <form> form one group per document and do not mix with the radios of a form.
  • :checked with a string checks the radio whose value equals the string. The same :checked="ClassName" on each radio therefore selects the one that matches. An empty string checks none.
  • Picking an unchecked radio fires input and change on that radio only; the radios it unchecks and a radio that is already checked fire nothing. ev.value is the picked radio's value.

Range

FormControls.rml
<input id="fc-volume" class="fc-range" type="range" min="0" max="100" step="5"
    :value="fc.Volume"/>
  • :value sets the slider. input fires for every change the user makes while dragging or stepping, change once at release and once per key step; both carry ev.value. :value writes the field on change, at release, not on every step of a drag. For a live readout while dragging, call() a function from on:input.
  • A value is clamped to min and max and snapped to step.
  • Gamepad and keyboard: the range is a focus stop. Left and Right step it (Up and Down for orientation="vertical"), Home and End jump to min and max. Up and Down on a horizontal range move focus, as anywhere else.

Select

FormControls.rml
<select id="fc-quality" :value="fc.Quality">
    <option value="low">Low</option>
    <option value="medium">Medium</option>
    <option value="high">High</option>
</select>
  • :value selects the option whose value matches and writes the pick. input and change fire when a pick changes the value.
  • On a closed select Enter, Space or gamepad accept open the list with the selected option highlighted. Up and Down move the highlight, Home and End jump to the first and last option, and Enter, Space or gamepad accept pick it. A mouse click on an option picks it.
  • Esc or gamepad back close the open list and keep the value; the Back stops there and does not close the screen. On a closed select Back works as usual.
  • Up and Down on a closed select move focus; they do not change the value.

Readout

FormControls.rml
<p id="fc-readout" class="fc-result">Subtitles: {{ fc.bSubtitles ? 'on' : 'off' }}, class: {{ fc.ClassName }}, volume: {{ fc.Volume }}, quality: {{ fc.Quality }}</p>

The readout reads the view model, so it shows the value after the setter has run.

Limits

  • A control's change never writes to a model field; call a view model function (Limits).
  • A value, checked or selected set by a binding or an attribute fires no event.
  • A control draws Chrome's native look, without its hover, active, focus and disabled looks. To style a control yourself, set appearance: none and use your own CSS.
  • A <button> never submits a <form>; only an enabled <input type="submit"> inside the form does. The type and value of a button are plain attributes.

Run it

Play in the map L_ArcRmlSamples and choose FormControls in the samples list. The second way is the console:

ArcRmlSamples.Open FormControls

Click the checkbox, pick a radio, press Left or Right on the range, press Enter on the select, move with Up and Down, press Enter again to pick. ArcRmlSamples.Close closes it again.

You should see the readout Subtitles: on, class: warrior, volume: 50, quality: medium, and it changes with each control you use.