• Molecule
  • CORE COMPONENT
  • Taxonomic name: M-FORM-AFFIX
  • Added on: v4.14.0 (11/10/19)
  • Updated on: v5.6.0 (20/04/21)

Form affix

Can be used as a prompt for user authentication when inputting incomplete policy numbers, values or sensitive data. Adds context for what information is required to be entered.


Design and usage

Structure

  • 6 grid column width (consistent with form UI).
  • Large or small labels permitted:

    • Large (20px text): Recommended for currency or data type symbols.
    • Small (16px text): Recommended for use with forms and form UI.
  • Prefix and suffix can be:

    • Numeric
    • Alphabetical
    • Alphanumeric
    • Symbol (£, $, % etc)
  • Supports all input types, ie. text box, drop down etc.
  • Icons: Recommended for use in conjunction with payment or card details (see FW card type icons).
  • Prefix and Suffix to sit adjoined to input field within their own individual bounding boxes; these can be labels only if being used for replaying data back to the user, ie. no input required (see 'Nested Slider' example).

Accessibility and screen readers

  • Colour contrast and typography WCAG compliant.
  • Permitted on following background colours:

    • White #FFFFFF (recommended)
  • Container heading: Allows for added context, improves scan-ability without the user having to read any supporting text (if any) and can aid user comprehension. Recommend for inclusion with optional removal if required.
  • Aria-invalid must be used to indicate when an error has occurred with this element.
  • Aria-describedby must be used to link any help, instructional and/or error text with the element/form fields.

Placement

  • Can be positioned beside a standalone input or within a container (eg. See FW pattern 'slider with manual inputs').
  • Can be used with various typographical lockups if required (see form UI and slider contextual examples).
  • Can accompany side-by-side input labels or stacked vertically where applicable (see example for card number entry).

Use case and exception scenarios

  • Used as prompt for user authentication when inputting incomplete policy numbers, values or sensitive data; adds context for what information is required to be entered.
  • Large labels: Recommended for currency or data/value type labels (eg. £, $, %), or for short labels requiring added prominence.
  • Small labels: Recommended for forms and form UI.

Design anatomy

  • Prefix - adjoined before an input field:

    • Bounding box: Left edges rounded rectangle 4px, bg colour #F5F8FC, outline #DCE6F4 (same as 'Date Picker', 'Horizontal Value Bar' , 'Toggle Display Results' styling).
    • Label: 10px horizontal padding from edge of prefix bounding box and input field, vertically centred in relation to bounding box

      • Large label: Source Sans Pro, 28px, regular
      • Small label: Source Sans Pro, 16px, semi-bold
  • Suffix - adjoined after input field:

    • Bounding box: Right edges rounded rectangle 4px, bg colour #F5F8FC, outline #DCE6F4
    • Label: 10px horizontal padding from edge of prefix bounding box and input field, vertically centred
  • Multiple - more than one prefix and/or suffix can be used
  • Icons- adjoined after input field:

    • Desktop/Tablet: To positioned with 20px horizontal padding from end of input or suffix where applicable.
    • Mobile: Can stack below if required. 20px vertical padding where applicable.

Examples

Prefix

Interactive example

Code example

<div class="m-form-row">
	<label class="a-label" for="...">...</label>
	<div class="m-form-row__content">
		<div class="m-form-affix">
			<div class="m-form-affix__label-wrapper">
				<span class="m-form-affix__label [ Modifier ]" aria-hidden="true">...</span>
				<input type="text" id="..." class="a-textbox" />
			</div>
		</div>
	</div>
</div>

Suffix

Interactive example

Code example

<div class="m-form-row">
	<label class="a-label" for="...">...</label>
	<div class="m-form-row__content">
		<div class="m-form-affix">
			<div class="m-form-affix__label-wrapper">
				<input type="text" id="..." class="a-textbox" />
				<span class="m-form-affix__label [ Modifier ]" aria-hidden="true">...</span>
			</div>
		</div>
	</div>
</div>

Prefix and suffix with smaller font, spacing and icon

Interactive example

Code example

<div class="m-form-row">
	<label class="a-label" for="...">...</label>
	<div class="m-form-row__content">
		<div class="m-form-affix [ Modifier ]">
			<div class="m-form-affix__label-wrapper">
				<span class="m-form-affix__label [ Modifier ]" aria-hidden="true">...</span>
				<input type="text" id="..." class="a-textbox" />
				<span class="m-form-affix__label [ Modifier ]" aria-hidden="true">...<span>...</span></span>
			</div>
			<img src="..." decoding="async" width="..." height="..." alt="...">
		</div>
	</div>
</div>

Ensure additional affix label content that requires spacing is wrapped in a span. For example:

<span class="m-form-affix__label [ Modifier ]" aria-hidden="true">...<span>...</span></span>

Prefix valid

Interactive example

Code example

<div class="m-form-row is-valid">
	<label class="a-label" for="...">...</label>
	<div class="m-form-row__content">
		<p class="m-form-row__validation-message">Valid input message</p>
		<div class="m-form-affix">
			<div class="m-form-affix__label-wrapper">
				<span class="m-form-affix__label [ Modifier ]" aria-hidden="true">...</span>
				<input type="text" id="..." class="a-textbox" />
			</div>
		</div>
	</div>
</div>

Suffix errored

Interactive example

Code example

<div class="m-form-row is-error" aria-invalid="true" aria-describedby="...">
	<label class="a-label" for="...">...</label>
	<div class="m-form-row__content">
		<p class="m-form-row__error-message" id="..."><span class="u-hidden--visually">Error: </span>...</p>
		<div class="m-form-affix">
			<div class="m-form-affix__label-wrapper">
				<input type="text" id="..." class="a-textbox" />
				<span class="m-form-affix__label [ Modifier ]" aria-hidden="true">...</span>
			</div>
		</div>
	</div>
</div>

Development and test

Notes for developers

See the main textbox reference developer notes for further information and additional options.

Labels

Ensure that the form label includes instructions for what value is expected, this is especially imporant for where the customer is expected to complete part of a policy number for example. This additional instruction can be visually hidden if required.

Input types

Care should be taken when choosing input field types for various uses, particularly with regard to number entry, as making the wrong selection could prevent users from inputting the required details into a form. For further information, see the form introduction page.

When disabling form elements, do not solely rely on the is-disabled class, but ensure that the disabled attribute is also set on the relevant form element or input. If an entire set of form elements is to be disabled, the is-disabled class and disabled attribute should be added directly to the fieldset instead, and not to each individual element within it. However if only one element from the set is disabled, then the class and attribute should be applied to that element only.

Aria usage for errors and help text

To aid screen reader users in completing forms without error and also with understanding and fixing any errors that have occured, some additional aria attributes are now recommended to be applied across all form fields/rows.

All form row help, explanatory text, form row instructions and form row errors must have a unique id assigned to them and be appropriately linked to either the individual form input or the form row using aria-describedby. This ensures that the help text is read out immediately on focus of the form input/fieldset. When there is more that one item that requires referencing within the aria-describedby attribute the id values must be supplied in the form of a space separated list. For example if there is an error with id of 'err1' and help text with id of 'help1' the value for the aria-describedby attribute would be 'err1 help1'.

All inline form error messages should start with the hidden text 'Error: ' so that when read by out by a screen reader it is immediately clear that the text being read is an error message.

All erroring form fields (or fieldset if a group or radios/checkboxes) must have aria-invalid="true" set on them, ensuring that when a user focus' on an errored form field, the field will be announced as invalid, so the user is then aware that there in an issue that requires fixing.

When linking help or errors, or even adding aria-invalid to the markup careful consideration must be taken as to where it is most appropriate to apply the value. The following rules should be used to decide where the attribute(s) should be applied.

  • Single form field - All attributes should be applied directly to that form field
  • Group of form fields but only one in error or help text applies to only one - Apply the attribute(s) to the only field in error or where the help text applies
  • Group of form field where all in error or the help text applies to all - Apply the attribute(s) to the groups surrounding fieldset (form row)

There may situations where more than one of these rules applies to the overall form row for example a date range where the instruction text applies to both fields so should be linked to the fieldset for the date range but one of the two fields is in error so the error should be linked to just that field not to the fieldset.

Important messages

To help those using assistive technologies, make sure that success/error messages which need to be announced to users have their aria attributes updated to role="alert" and/or aria-live="assertive".

Using autocomplete

Users appreciate when websites save them time by automatically filling common fields like names, email addresses and other frequently used fields, plus it helps to reduce potential input errors, especially on virtual keyboards and small devices.

Browsers use many methods to determine which fields they can auto-populate based on previously specified data by the user, and you can give hints to the browser by providing both the name attribute and the autocomplete attribute on each input element.

Further details can be found in the developer notes on the form introduction page.


Classes overview

The following table gives you a quick overview of the CSS classes that can be applied.

Class Outcome Required Applied to Comments
.m-form-affix Base class for affix Yes .m-form-row__content > div  
.m-form-affix--full-width Modifier to push affix area to span full width of the form row   .m-form-affix For use with the slider range component
.m-form-affix__label-wrapper For wrapping an affix to a form element Yes .m-form-affix > div Required for wrapping the affix elements with the form element
.m-form-affix__label Affix spacing and styling Yes .m-form-affix__label-wrapper > span  
.m-form-affix__label--small Optional modifier class for reduced font size to the affix   .m-form-affix__label  
.m-form-affix--icon Spacing modifier class when adding an icon to the affix form row   .m-form-affix Adjusts the spacing to the row to accomodate the icon over different viewports

Component releases

  • Added on: v4.14.0 (11/10/19)
  • Updated on: v5.6.0 (20/04/21)

Latest update:

  • updated: To improve page load and layout times the additional attributes decoding="async", width and height must be set on all inline images.

Full version history

A full history of changes and enhancements detailing all minor and major updates to the component.

View full version history

Want something new in Framework, or to chat about an issue you're having with it?

Contact the team