Origami Frontend Components & Services

JSDoc: o-forms

ErrorSummaryElement

Properties

  • element - (type: HTMLInputElement) the associated element
  • id - (type: string) the input element's id
  • valid - (type: boolean) was the user's value valid?
  • error - (type: string) the error message for this element
  • field - (type: HTMLElement) a containing o-forms-field element
  • label - (type: HTMLLabelElement) an associated label element

Type

object

Links

new ErrorSummary(elements, headingMessage)

Class constructor.

parameter type default description
elements (optional) Array.<ErrorSummaryElement> An array of objects, where each object describes an invalid input element
headingMessage (optional) string 'There is a problem' A message to show in the header. It defaults to: 'There is a problem'

Methods

Example

const elementsExample = [
		{
			id: 'text-input',
			valid: false,
			error: 'Please fill out this field',
			label: 'Input Label',
			element: <Element />,
		},
		{...},
	];
	new ErrorSummary(example, 'This is a heading message')

Links

new Forms(formElement, options)

Class constructor.

parameter type default description
formElement (optional) HTMLElement The form element in the DOM
options (optional) object {} An options object for configuring the form

Methods

Links

new Input(element)

Class constructor.

parameter type default description
element (optional) HTMLElement An input element in the DOM

Methods

Links

new State(...)

Class constructor.

parameter type default description
inputs (optional) RadioNodeList A NodeList of radio input elements
opts boolean | object an object of options
opts.iconOnly string [null] - when true display an icon only, hiding the status label

Methods

Links

ErrorSummary#createSummary

Instance Method

Generate Node to hold list of invalid inputs

Returns

  • HTMLDivElement - - a div full of error messages

Links

ErrorSummary.createList(inputs)

Static Method

Generate list of anchors

parameter type default description
inputs Array.<ErrorSummaryElement> element descriptors

Returns

  • HTMLUListElement - - the list

Links

ErrorSummary.createItem(input)

Static Method

Generate an item for the error summary

parameter type default description
input (optional) object The input object to construct an error summary item for

Returns

  • Element - - li

Links

ErrorSummary.createAnchor(input)

Static Method

Generate anchor element to point at invalid input

parameter type default description
input (optional) object The input object to construct an anchor for

Returns

  • Element - - a

Links

Forms.getDataAttributes(formElement)

Static Method

Get the data attributes from the formElement. If the form is being set up declaratively, this method is used to extract the data attributes from the DOM.

parameter type default description
formElement HTMLElement The message element in the DOM

Returns

  • Object.<string, any> - - The options

Links

Forms#handleEvent(event)

Instance Method

Event Handler

parameter type default description
event object The event emitted by element/window interactions

Returns

  • void

Links

Forms#validateFormInputs

Instance Method

Form validation Validates every element in the form and creates input objects for the error summary

Returns

Links

Forms#setState(...)

Instance Method

parameter type default description
state string name of the input fields to add state to
name string type of state to apply — one of 'saving', 'saved', 'none'
options object an object of options
options.iconLabel string [null] - customise the label of the state, e.g. the saved state defaults to "Saving" but could be "Sent"
options.iconOnly boolean [false] - when true display an icon only, hiding the status label

Links

Forms#destroy

Instance Method

Destroy form instance

Links

Forms.init(rootEl, opts)

Static Method

Initialise form component.

parameter type default description
rootEl HTMLElement | string The root element to intialise a form in, or a CSS selector for the root element
opts (optional) object {} An options object for configuring the banners

Returns

  • Forms | Array.<Forms> - - The newly instantiated Form or Forms

Links

Input#handleEvent(event)

Instance Method

Event Handler

parameter type default description
event object The event emitted by element/window interactions

Links

Input#validate(event)

Instance Method

Input validation Conditions for input validation

parameter type default description
event FocusEvent [] - The event which has caused re-validation.

Returns

  • boolean - - is the input valid?

Links

State#set(state, label)

Instance Method

State setter

parameter type default description
state string type of state to display
label string customise the label of the state, e.g. the saved state defaults to "Saving" but could be "Sent"

Links

new Forms(formElement, options)

Class constructor.

parameter type default description
formElement (optional) HTMLElement The form element in the DOM
options (optional) object {} An options object for configuring the form

Methods

Links

Status
active
Switch component view

GitHub: o-forms@9.5.0

Install o-forms

If using the Build Service, add o-forms@^9.5.0 to your script and link tags.

If using the npm package manager for a Manual Build, run npm install --save-peer "@financial-times/o-forms@^9.5.0".

Help & Support

o-forms is maintained directly by the Origami team. If you have any questions about o-forms or Origami in general, we are happy to help. 😊

Slack: #origami-support
Email: origami.support@ft.com

Feedback / Issues

To report a bug or request features please create an issue on Github. For support or general feedback please get in touch 😊

Slack: #origami-support
Email: origami.support@ft.com