Origami Frontend Components & Services

JSDoc: o-forms

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) HTMLFormElement The form element in the DOM
options (optional) FormsOptions {} 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

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

FormsOptions

An options object for configuring the form.

Properties

  • errorSummary - (type: boolean) Display an error summary at the top of the form as part of `o-forms` validation.
  • preventSubmit - (type: boolean) Prevent form submission after `o-froms` validation – see the `oForms.submit` event to manually submit the form after validation. This does not apply when `useBrowserValidation` is true.
  • useBrowserValidation - (type: boolean) Do not use `o-forms` validation, rely on the browser's built-in validation instead.

Type

Object

Links

FormsSubmitEvent

An event emitted when the form is submitted by the userand `o-forms` has completed validation.

Properties

  • detail - (type: object) The event detail.
  • detail.instance - (type: object) The instance of `o-forms`.
  • detail.valid - (type: boolean) The validity of the `o-forms` instance.

Type

Event

Links

Banner#render

Instance Method

Render the banner.

Returns

  • void

Links

Banner#open

Instance Method

Open the banner.

Returns

  • void

Links

Banner#close

Instance Method

Close the banner.

Returns

  • void

Links

Banner#buildBannerElement(bannerElement)

Instance Method

Build a full banner element. This is used when no banner or a partial banner exists in the DOM.

parameter type default description
bannerElement (optional) HTMLElement The banner element to build around

Returns

  • HTMLElement - Returns the new banner element

Links

Banner#buildCloseButtonElement

Instance Method

Build a close button element.

Returns

  • HTMLElement - Returns the new close button element

Links

Banner.getOptionsFromDom(bannerElement)

Static Method

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

parameter type default description
bannerElement HTMLElement The banner element in the DOM

Returns

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

Links

Banner#destroy

Instance Method

Undo the init method

Links

Banner.init(rootElement, options)

Static Method

Initialise banner components.

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

Returns

  • Banner | Array.<Banner> - - The newly instantiated Banner (or Banners, if rootElement was not a banner)

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

<anonymous>~oFormsSubmitEvent

Inner Property

Type

  • FormsSubmitEvent

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) HTMLFormElement The form element in the DOM
options (optional) FormsOptions {} An options object for configuring the form

Methods

Links

Status
active
Switch component view

GitHub: o-forms@9.11.0

Install o-forms

If using the Build Service, add o-forms@^9.11.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.11.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