If your fields have proper labels, the form guide finds them.
Which fields get an icon#
<input>,<select>and<textarea>fields. Inputs of typehidden,submit,button,reset,imageandfileare left out.- A group of radio buttons (radio buttons sharing a
name) gets one icon for the whole group. - If a slider (
type="range") shares its label with a text box in the same row, only the text box gets an icon. - The field must have a label. If the guide can't find one, the field gets no icon.
The icon goes inside the field's <label> when there is one. Otherwise it
goes just after the field. Fields added to the page later (for example, the
next step of a multi-step form) get icons automatically. A field never gets
two icons.
How it finds the label#
It tries these in order and uses the first one it finds:
data-formguide-field-label="..."on the field.- For radio groups: a label or short text near the group, then the
<fieldset>'s<legend>, then the heading above it. - A
<label for="field-id">. - A
<label>wrapped around the field. aria-labelon the field.aria-labelledbyon the field.- A nearby
<label>or element with classlabel, up to three levels up. - A heading right above the field.
- Short text (
<p>or<span>) before the field in its row. - Any heading above the field, inside the form.
- The field's
placeholder. - The field's
name, made readable (date_of_birthbecomes "date of birth").
Attributes you can add to your fields#
| Attribute | Put it on | What it does |
|---|---|---|
data-formguide="skip" |
a field or group | No icon for this field. It's also left out of the list of other questions the agent sees. Use it for the second and third boxes of a date split into day, month and year. |
data-formguide="extract" |
a field or group | Lets the agent fill in this field. The panel gets a Done button. See Letting the agent fill in fields. |
data-formguide-field-label="..." |
a field or group | The question to use, instead of any label found on the page. Use it when a field's own label is only part of the question, e.g. "Day" for "Date of birth". |
data-formguide-field="key" |
an element holding <button>s |
Treats a row of buttons as one question. See Questions made of buttons. |
data-formguide-form |
an element around your fields | If your fields aren't inside a <form>, the guide treats the nearest element with this attribute as the form. |
A date of birth split into three boxes, with one icon for the whole question:
<span class="label">Date of birth</span>
<input name="dob_day" aria-label="Day" data-formguide-field-label="Date of birth">
<input name="dob_month" aria-label="Month" data-formguide="skip">
<input name="dob_year" aria-label="Year" data-formguide="skip">
Help text#
If a field has help text, the agent is told about it. The guide finds it here:
- the element named by the field's
aria-describedby, or - a
<small>, or an element with classhelp-textorform-text, right after the field.
<label for="occupation">Your job</label>
<input id="occupation" name="occupation" aria-describedby="occupation-help">
<p id="occupation-help">As you'd describe it to a friend.</p>
Questions made of buttons#
Some forms show a question as a row of buttons (Yes/No, cards to choose
from, tick lists) with no input behind them. Mark the element around the
buttons with data-formguide-field and a short key:
<div data-formguide-field="cover_reason" data-formguide-field-label="What is the cover for?">
<button type="button">Mortgage</button>
<button type="button">Family</button>
<button type="button">Income</button>
</div>
The question comes from data-formguide-field-label. Without it, the guide
uses a <label> or .label element inside the group, or else the nearest
heading above the group. A group with none of these gets no icon.
<div data-formguide-field="cover_reason">
<div class="label">What is the cover for?</div>
<button type="button">Mortgage</button>
<button type="button">Family</button>
</div>
The icon goes in that <label> or .label element, else in a heading just
above the group, else at the start of the group.
The text on the buttons is sent to the agent as the choices. If the agent fills in the answer, it clicks the matching buttons, so your own click handlers record the answer as usual.
Choosing which fields get help#
There are four ways to leave fields out, and you can combine them:
data-formguide="skip"on the field itself.exclude(ordata-exclude): a CSS selector. Matching fields are left out.fieldRules(ordata-field-rules): a list of rules. See below.- With
attach(), only fields insidecontainerare included.
Field rules#
fieldRules: {
mode: 'blocklist', // or 'allowlist'
entries: [
{ type: 'field_name', pattern: 'email' }, // matches name="email" or id="email"
{ type: 'css_selector', pattern: '.no-help' } // matches any CSS selector
]
}
| Setting | Meaning |
|---|---|
mode: 'blocklist' |
Fields that match a rule get no icon. |
mode: 'allowlist' |
Only fields that match a rule get an icon. |
type: 'field_name' |
Matches a field whose name or id is exactly the pattern. |
type: 'css_selector' |
Matches a field that fits the CSS selector. |
An empty entries list does nothing.