• Atom
  • CORE COMPONENT
  • Taxonomic name: A-PLUSMINUS
  • Extension: FORMS-EXTENDED-B
  • Added on: v3.0.0 (15/09/17)
  • Updated on: v5.9.0 (13/07/21)

Plus/minus number textbox

This control allows users to select a value through interaction with the plus and minus buttons, or by directly entering a value into the field.


Design and usage

  • Can be used to enter values between a range of zero to nine
  • In instances where the highest value we require is nine (or more), and no further information is required, display a message to the user to inform them that no further information is required.
  • If higher increments or further information is required, an alternative such as drop down list or textbox should be used.
  • 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.

Examples

Standard plus/minus textbox

Interactive example

Code example

<div class="m-form-row">
	<label class="a-label" for="...">...</label>
	<div class="m-form-row__content">
		<input type="number" id="..." name="..." class="a-textbox" value="..." min="..." max="..." data-module="a-plusminus" />
	</div>
</div>

Valid plus/minus textbox

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">...</p>
		<input type="number" id="..." name="..." class="a-textbox" value="..." min="..." max="..." data-module="a-plusminus" />
	</div>
</div>

Errored plus/minus textbox

Interactive example

Code example

<div class="m-form-row is-error">
	<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>
		<input type="number" id="..." name="..." class="a-textbox" value="..." min="..." max="..." aria-invalid="true" aria-describedby="..." data-module="a-plusminus" />
	</div>
</div>

Disabled plus/minus textbox

Interactive example

Code example

<div class="m-form-row is-disabled">
	<label class="a-label" for="...">...</label>
	<div class="m-form-row__content">
		<input type="number" id="..." name="..." class="a-textbox" value="..." min="..." max="..." disabled data-module="a-plusminus" />
	</div>
</div>

Required plus/minus textbox

<div class="m-form-row">
	<label class="a-label" for="...">...</label>
	<div class="m-form-row__content">
		<input type="number" id="..." name="..." class="a-textbox" value="..." min="..." max="..." aria-required="true" data-module="a-plusminus" />
	</div>
</div>

Development and test

Notes for developers

Field labels should be displayed outside of the input not inside.

Line-breaks are automatically removed from the input value.

Some browsers include the functionality to be able to show the value of any password entered into a password field. Do not attempt to either recreate this functionality or turn it off.

Ensure that the autocomplete attribute is set for off for any field that may have privacy concerns eg. passwords, card/account numbers etc.

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.

If the native form validation needs to be disabled set the novalidate attribute on the form.

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.

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.

Controling the plus/minus number textbox programatically

Plus/minus number textbox can be controlled programatically to set the displayed value and the minimum and maximum possible values. The following methods are available for use:

Method Description
setValue( 5 ) Sets the value of the input to the integer value passed in.
setMin( 0 ) Sets the minimum value allowed for the input to the integer value passed in. If the input value is lower than the new minimum the value will be updated to the new minimum.
setMax( 10 ) Sets the maximum value allowed for the input to the integer value passed in. If the input value is hight than the new maximum the value will be updated to the new maximum.

For example:

document.addEventListener( 'frameworkready', function () {
	FRAMEWORK.require([ 'blocks/a-plusminus' ], function ( aPlusminusModule ) {
		var plusminusEl = document.querySelector( '#inputId' ),
			plusminusInstance = aPlusminusModule.initInstance( plusminusEl );		plusminusInstance.setValue( 5 );
	});
});

Changing locale settings

The accessible labels for the plus and minus buttons can be updated for a particular locale.

en: {
	aPlusMinus : {
		plus : 'plus',
		minus : 'minus',
	},
},

For more information on this, see our page on how to change locale settings within JavaScript.

Extension component

This component forms part of the 'forms_extended_b' extension and so requires an additional stylesheet to be loaded in order to be used; include the following code in the header of your page to attach the relevant additional stylesheet:

<link media="all" href="./assets/[ theme type ]/[ release version ]/[ organisation ]/[ theme name ]/css/forms_extended_b.css" rel="stylesheet" />

Notes for testers

  • Number inputs are understood by all browsers, so they fall back to being a standard text input field. This means that they may allow the entry of invalid characters, so any invalid entries should be highlighted when the form is submitted like any other errors.
  • Ensure that all form fields have a correctly associated label. This not only provides context to each field for assistive technology users but also a larger clickable area to select the field. Clicking/pressing on a label for a single input field should cause the input to gain focus (as will clicking on the plus / minus buttons).
  • Sensible minimum / maximum values must be set to allow the buttons work (negative numbers are permissible).
  • Ensure that autofill is not available for sensitive fields such as password, card/account number etc.
  • Users should be able to copy and paste if necessary.

Keyboard operations

TAB

Tabbing to an input field should make the input clearly visually different so that the focus point on the page is obvious to the user.

Component releases

  • Added on: v3.0.0 (15/09/17)
  • Updated on: v5.9.0 (13/07/21)

Latest update:

  • updated: Plus/minus number textbox can now be controlled programatically to set the displayed value and the minimum and maximum possible values.

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