Element: <oj-switch>

Oracle® JavaScript Extension Toolkit (JET)
16.0.0

F83701-01

Since:
  • 0.7.0
Module:
  • ojswitch

QuickNav

Attributes


The oj-switch component enhances input element and manages the selection of Boolean values.

Validation and Messaging

An editable component runs validation (normal or deferred) based on the action performed on it (either by end-user or page author), and the state it was in when the action occurred. Examples of actions are - creating a component, user changing the value of the component by interacting with it, the app setting a value programmatically, the app calling the validate() method etc. At the time the action occurs, the component could already be showing errors, or can have a deferred error or have no errors.

These factors also determine whether validation errors/messages get shown to the user immediately or get deferred. The following sections highlight the kinds of validation that are run and how messages get handled.

Normal Validation

Normal validation is run in the following cases on the display value, using the converter and validators (this includes async-validators) set on the component, and validation errors are reported to user immediately.
  • When value changes as a result of user interaction all messages are cleared, including custom messages added by the app, and full validation is run on the UI value. The steps performed are outlined below.
    1. All messages are cleared and messagesCustom property is cleared
    2. If no converter is present then processing continues to next step. If a converter is present, the UI value is first converted (i.e., parsed). If there is a parse error then the messages are shown and processing returns.
    3. If there are no validators setup for the component then the value is set on the component. Otherwise all validators are run in sequence using the parsed value from the previous step. The implicit required is run first if the component is marked required. When a validation error is encountered it is remembered and the next validator in the sequence is run.
      • NOTE: The value is trimmed before required validation is run
    4. At the end of the validation run if there are errors, the messages are shown and processing returns. If there are async-validators, those errors are shown as soon as they come in, and not until all validators, sync and async validators, are complete, does processing return, that is, value and valid are updated. If there are no errors, then the value property is updated and the formatted value displayed on the UI.
  • When the validate method is called by app, all messages are cleared and full validation run using the display value. See validate method on the sub-classes for details. Note: JET validation is designed to catch user input errors, and not invalid data passed from the server; this should be caught on the server.
  • When certain properties change through programmatic intervention by app, the component determines whether it needs to run normal validation based on the state the component is in. Refer to the Mixed Validation section below for details.

Deferred Validation

Deferred validation is run in the following cases on the component value using the implicit required validator if required is true, and validation errors are deferred, i.e., not shown to user immediately. Refer to the Showing Deferred Messages section to understand how deferred messages can be shown.
  • When a component is created and it is required deferred validation is run and no messages are cleared prior to running validation. Refer to the Validators Participating in Deferred Validation section for details.
  • When the value property changes due to programmatic intervention deferred validation is run, after all messages and messagesCustom property are cleared.
  • When the reset method is called, deferred validation is run after all messages and messagesCustom property are cleared.
  • When certain properties change through programmatic intervention by app, the component determines whether it needs to run deferred validation based on the state the component is in. Refer to the Mixed Validation section below for details.

Mixed Validation

Either deferred or normal validation is run in the following cases based on the state the component is in and any validation errors encountered are either hidden or shown to user.
  • when disabled property changes. See disabled property for details.
  • when refresh method is called. See refresh method for details.
  • when converter property changes. Not all EditableValue components have the converter property. See the sub-classes that have the converter property for details, e.g., oj.ojInputText#converter.
  • when required property changes. Not all EditableValue components have the required property. See the sub-classes that have the required property for details, e.g., oj.inputBase#required.
  • when validators property changes. Not all EditableValue components have the validators property. See the sub-classes that have the validators property for details, e.g., oj.inputBase#validators.
  • when asyncValidators property changes. Not all EditableValue components have the asyncValidators property. See the sub-classes that have the asyncValidators property for details, e.g., oj.inputBase#asyncValidators.

Showing Deferred Messages

Deferred validation messages are displayed only when page author requests for it explicitly in one of the following ways:

Validators Participating in Deferred Validation

The required validator is the only validator type that participates in deferred validation. The required property needs to be set to true for the required validator to run.

User Assistance Text

User assistive text provides guidance to help the user understand what data to enter or select.

In the Redwood theme, by default all user assistance text shows inline. For input components, it shows when the field takes focus. In other components it shows all the time. See the user-assistance-density property for other ways the user assistance text can render, like in 'compact' mode, it will render as an icon on the label which when clicked will show the user assistance text in a notewindow.

The JET form component properties that are used for user assistance text are help.instruction, validator and converter hints, and help-hints. In the Redwood theme for clarity only one user assistance text shows to the user. The precedence rules are:

  • help.instruction shows;
  • if no help.instruction, then validator hint shows;
  • if no help.instruction or validator hint, then help-hints.definition shows;
  • if no help.instruction, validator hint, or help-hints.definition, then converter hint shows.
  • help-hints.source always shows along side the above.

In the Alta theme all the user assistance text are displayed to the user. By default help.instruction and the validator/converter hints show in a notewindow that is displayed when the field takes focus. The help-hints render as a help icon on the label and when clicked show in a notewindow. Note: If there is no label, help-hints help icon will not show.

Sometimes a validator or converter hints shows that you do not want. To not show it, set the display-options.validator-hint and/or display-options.converter-hint property to 'none'.

required and placeholder properties also can be used to guide the user. In Redwood, a required field shows the word Required under the field when the field is empty and does not have focus. Placeholder is shown when the field is empty and has focus.

Touch End User Information

Target Gesture Action
Switch Thumb Tap Toggle switch value

Keyboard End User Information

Target Key Action
Switch Thumb Enter or Space Toggle switch value
Switch Thumb Tab In Set focus to the thumb. If hints, title or messages exist in a notewindow, pop up the notewindow.

Disabled items can not receive keyboard focus.

Accessibility

The component is accessible; it sets and maintains the appropriate aria- attributes, like aria-checked and aria-disabled.

For accessibility, set label-hint or associate an oj-label with the form component. If there is no visible label, then to make this accessible to screen reader users, set the label-hint and label-edge='none' which renders an aria-label with the label-hint text. If using an oj-label instead of the label-hint attribute, then put an id on the form component element, and set the oj-label's for attribute to be the form component's id.

Disabled content: JET supports an accessible luminosity contrast ratio, as specified in WCAG 2.0 - Section 1.4.3 "Contrast", in the themes that are accessible. (See the "Theming" chapter of the JET Developer Guide for more information on which themes are accessible.) Note that Section 1.4.3 says that text or images of text that are part of an inactive user interface component have no contrast requirement. Because disabled content may not meet the minimum contrast ratio required of enabled content, it cannot be used to convey meaningful information.

Setting the Value Attribute

The value attribute should be Boolean. If the value attribute is undefined, then it is false.


Usage

Signature:

interface SwitchElement

Typescript Import Format
//To typecheck the element APIs, import as below.
import { SwitchElement } from "ojs/ojswitch";

//For the transpiled javascript to load the element's module, import as below
import "ojs/ojswitch";

For additional information visit:

Note: Application logic should not interact with the component's properties or invoke its methods until the BusyContext indicates that the component is ready for interaction.


Styling Classes

.oj-focus-highlight
Under normal circumstances this class is applied automatically. It is documented here for the rare cases that an app developer needs per-instance control.

The oj-focus-highlight class applies focus styling that may not be desirable when the focus results from pointer interaction (touch or mouse), but which is needed for accessibility when the focus occurs by a non-pointer mechanism, for example keyboard or initial page load.

The application-level behavior for this component is controlled in the theme by the $focusHighlightPolicy SASS variable; however, note that this same variable controls the focus highlight policy of many components and patterns. The values for the variable are:

nonPointer: oj-focus-highlight is applied only when focus is not the result of pointer interaction. Most themes default to this value.
all: oj-focus-highlight is applied regardless of the focus mechanism.
none: oj-focus-highlight is never applied. This behavior is not accessible, and is intended for use when the application wishes to use its own event listener to precisely control when the class is applied (see below). The application must ensure the accessibility of the result.

To change the behavior on a per-instance basis, the application can set the SASS variable as desired and then use event listeners to toggle this class as needed.
Example
<oj-switch class="oj-focus-highlight">
  <!-- Content -->
</oj-switch>
.oj-switch
Top level switch class.

CSS Variables

See JET CSS Variables for additional details.
Name Type Description
--oj-switch-track-height <length> Switch track height
--oj-switch-track-width <length> Switch track width
--oj-switch-track-border-radius <length> | <percentage> Switch track border radius
--oj-switch-thumb-to-track-horizontal-margin <length> Switch thumb to track horizontal margin
--oj-switch-thumb-height <length> Switch thumb height
--oj-switch-thumb-width <length> Switch thumb width
--oj-switch-thumb-border-radius <length> | <percentage> Switch thumb border radius
Enabled
CSS variables used by oj-switch when enabled
Name Type Description
--oj-switch-track-bg-color <color> Switch track background color when enabled
--oj-switch-track-border-color <color> Switch track border color when enabled
--oj-switch-thumb-bg-color <color> Switch thumb background color when enabled
--oj-switch-thumb-border-color <color> Switch thumb border color when enabled
--oj-switch-thumb-box-shadow Switch thumb box shadow when enabled
Hovered
CSS variables used by oj-switch when hovered
Name Type Description
--oj-switch-track-bg-color-hover <color> Switch track background color when hovered
--oj-switch-track-border-color-hover <color> Switch track border color when hovered
--oj-switch-track-border-color-hover <color> Switch track border color when hovered
--oj-switch-thumb-bg-color-hover <color> Switch thumb background color when hovered
--oj-switch-thumb-border-color-hover <color> Switch thumb border color when hovered
--oj-switch-thumb-box-shadow-hover Switch thumb box shadow when hovered
Selected hovered
CSS variables used by oj-switch when selected and hovered
Name Type Description
--oj-switch-track-bg-color-selected-hover <color> Switch track background color when selected and hovered
--oj-switch-track-border-color-selected-hover <color> Switch track border color when selected and hovered
--oj-switch-thumb-bg-color-selected-hover <color> Switch thumb background color when selected and hovered
--oj-switch-thumb-border-color-selected-hover <color> Switch thumb border color when selected and hovered
--oj-switch-thumb-box-shadow-selected-hover Switch thumb box shadow when selected and hovered
Active
CSS variables used by oj-switch when active
Name Type Description
--oj-switch-track-bg-color-active <color> Switch track background color when active
--oj-switch-track-border-color-active <color> Switch track border color when active
--oj-switch-thumb-bg-color-active <color> Switch thumb background color when active
--oj-switch-thumb-border-color-active <color> Switch thumb border color when active
--oj-switch-thumb-box-shadow-active Switch thumb box shadow when active
--oj-switch-thumb-width-active <length> Switch thumb width when active
Selected active
CSS variables used by oj-switch when selected and active
Name Type Description
--oj-switch-track-bg-color-selected-active <color> Switch track background color when selected and active
--oj-switch-track-border-color-selected-active <color> Switch track border color when selected and active
--oj-switch-thumb-bg-color-selected-active <color> Switch thumb background color when selected and active
--oj-switch-thumb-border-color-selected-active <color> Switch thumb border color when selected and active
--oj-switch-thumb-box-shadow-selected-active Switch thumb box shadow when selected and active
Disabled
CSS variables used by oj-switch when disabled
Name Type Description
--oj-switch-track-bg-color-disabled <color> Switch track background color when disabled
--oj-switch-track-border-color-disabled <color> Switch track border color when disabled
--oj-switch-thumb-bg-color-disabled <color> Switch thumb background color when disabled
--oj-switch-thumb-border-color-disabled <color> Switch thumb border color when disabled
Selected disabled
CSS variables used by oj-switch when selected and disabled
Name Type Description
--oj-switch-track-bg-color-selected-disabled <color> Switch track background color when selected and disabled
--oj-switch-track-border-color-selected-disabled <color> Switch track border color when selected and disabled
--oj-switch-thumb-bg-color-selected-disabled <color> Switch thumb background color when selected and disabled
--oj-switch-thumb-border-color-selected-disabled <color> Switch thumb border color when selected and disabled

Slots

JET components that allow child content support slots. Please see the slots section of the JET component overview doc for more information on allowed slot content and slot types.

contextMenu

The contextMenu slot is set on the oj-menu within this element. This is used to designate the JET Menu that this component should launch as a context menu on right-click, Shift-F10, Press & Hold, or component-specific gesture. If specified, the browser's native context menu will be replaced by the JET Menu specified in this slot.

The application can register a listener for the Menu's ojBeforeOpen event. The listener can cancel the launch via event.preventDefault(), or it can customize the menu contents by editing the menu DOM directly, and then calling refresh() on the Menu.

To help determine whether it's appropriate to cancel the launch or customize the menu, the ojBeforeOpen listener can use component API's to determine which table cell, chart item, etc., is the target of the context menu. See the JSDoc of the individual components for details.

Keep in mind that any such logic must work whether the context menu was launched via right-click, Shift-F10, Press & Hold, or component-specific touch gesture.

Deprecated:
Since Description
13.0.0 This web component no longer supports launching a context menu.

Attributes

(nullable) described-by :string

The oj-label sets the described-by attribute programmatically on the form component. This attribute is not meant to be set by an application developer directly. The described-by is copied to the aria-describedby attribute on the component's inner dom element, and it is needed for accessibility.
Since:
  • 4.0.0
Names
Item Name
Property describedBy
Property change event describedByChanged
Property change listener attribute (must be of type function, see Events and Listeners for additional information.) on-described-by-changed

disabled :boolean

Whether the component is disabled. The element's disabled property is used as its initial value if it exists, when the attribute is not explicitly set. When neither is set, disabled defaults to false.

Default Value:
  • false
Names
Item Name
Property disabled
Property change event disabledChanged
Property change listener attribute (must be of type function, see Events and Listeners for additional information.) on-disabled-changed

display-options :Object

Display options for auxiliary content that determines whether or not it should be displayed.

In the Redwood theme, the sub-properties of the display-options configure whether or not the types of information is shown. The values of these sub-properties are either 'display' or 'none'.

In the Alta theme the sub-properties of the display-options configure aspects of visual behavior such as where types of information is shown. The values of these sub-properties are specified either as an array of strings or a string. When an array is specified the first display option takes precedence over the second display option and so on.

When display-options changes due to programmatic intervention, the component updates its display to reflect the updated choices. For example, if you don't want to show the converter hint, set the display-options.converter-hint to 'none'.

A side note: help.instruction and message detail text can include formatted HTML text, whereas hints and message summary text cannot. If you use formatted text, it should be accessible and make sense to the user if formatting wasn't there. The allowed html tags are: span, b, i, em, br, hr, li, ol, ul, p, small, pre. To format the help.instruction, you could do this:

<html>Enter <b>at least</b> 6 characters</html>

Since:
  • 0.7
Names
Item Name
Property displayOptions
Property change event displayOptionsChanged
Property change listener attribute (must be of type function, see Events and Listeners for additional information.) on-display-options-changed

display-options.converter-hint :Array<'placeholder'|'notewindow'|'none'>|'placeholder'|'notewindow'|'display'|'none' display-options.converter-hint :('display'|'none')

Display options for auxiliary converter hint text. The supported attribute values are theme dependent.

In the Redwood theme, this attribute determines whether or not the converter hint should be displayed. The supported values are 'display' and 'none'. If you don't want to show the converter hint, set display-options.converter-hint to 'none'. It defaults to 'display'. To control where the hints display, e.g., inline or in a notewindow, then use the user-assistance-density attribute.

In the Alta theme this attribute determines where and whether to show the converter hint. If you don't want to show the converter hint, set display-options.converter-hint to 'none'. The Alta theme supports these attribute values, most of which are deprecated: Array<'placeholder'|'notewindow'|'none'>|'placeholder'|'notewindow'|'none'. The default is ['placeholder','notewindow'].

Deprecated:
Since Value Description
9.1.0 Array<'placeholder'|'notewindow'|'none'>,'placeholder','notewindow' These types are no longer supported. They are used for the Alta theme only. The Redwood theme uses 'display'|'none' and the user-assistance-density attribute.
Since:
  • 9.1.0
Names
Item Name
Property displayOptions.converterHint

display-options.help-instruction :Array<'notewindow'|'none'>|'notewindow'|'none'

Display options for auxiliary help instruction text that determines where it should be displayed in relation to the component.
Deprecated:
Since Description
9.0.0 If you want none, remove help-instruction attribute.
Default Value:
  • ['notewindow']
Since:
  • 9.0.0
Names
Item Name
Property displayOptions.helpInstruction

display-options.messages :Array<'inline'|'notewindow'|'none'>|'inline'|'notewindow'|'display'|'none' display-options.messages :('display'|'none')

Display options for auxiliary message text. The supported attribute values are theme dependent.

In the Redwood theme, this attribute determines whether or not the messages should be displayed. The supported values are 'display' and 'none'. If you don't want to show messages, set display-options.messages to 'none'. It defaults to 'display'. To control where the messages display, e.g., inline or in a notewindow, then use the user-assistance-density attribute.

In the Alta theme this attribute determines where and whether to show the messages. If you don't want to show messages, set display-options.messages to 'none'. The Alta theme supports these attribute values, most of which are deprecated: Array<'inline'|'notewindow'|'none'>|'inline'|'notewindow'|'none'. The default is ['inline'].

Deprecated:
Since Value Description
9.1.0 Array<'inline'|'notewindow'|'none'>,'inline','notewindow' These types are no longer supported. They are used for the Alta theme only. The Redwood theme uses 'display'|'none' and the user-assistance-density attribute.
Since:
  • 9.1.0
Names
Item Name
Property displayOptions.messages

display-options.validator-hint :Array<'notewindow'|'none'>|'notewindow'|'display'|'none' display-options.validator-hint :('display'|'none')

Display options for auxiliary validator hint text. The supported attribute values are theme dependent.

In the Redwood theme, this attribute determines whether or not the validator hint should be displayed. The supported values are 'display' and 'none'. If you don't want to show the validator hint, set display-options.validator-hint to 'none'. It defaults to 'display'. To control where the hints display, e.g., inline or in a notewindow, then use the user-assistance-density attribute.

In the Alta theme this attribute determines where and whether to show the validator hint. If you don't want to show the validator hint, set display-options.validator-hint to 'none'. The Alta theme supports these attribute values, most of which are deprecated: Array<'notewindow'|'none'>|'notewindow'|'none'. The default is ['notewindow'].

Deprecated:
Since Value Description
9.1.0 Array<'notewindow'|'none'>,'notewindow' These types are no longer supported. They are used for the Alta theme only. The Redwood theme uses 'display'|'none' and the user-assistance-density attribute.
Since:
  • 9.1.0
Names
Item Name
Property displayOptions.validatorHint

help :Object

Form component help information.
Since:
  • 0.7.0
Names
Item Name
Property help
Property change event helpChanged
Property change listener attribute (must be of type function, see Events and Listeners for additional information.) on-help-changed

help.instruction :string

A type of user assistance text. User assistance text is used to provide guidance to help the user understand what data to enter or select.

In the Redwood theme for clarity only one user assistance text shows to the user. The precedence rules are:

  • help.instruction shows;
  • if no help.instruction, then validator hint shows;
  • if no help.instruction or validator hint, then help-hints.definition shows;
  • if no help.instruction, validator hint, or help-hints.definition, then converter hint shows.
  • help-hints.source always shows along side the above.

In the Redwood theme, by default all user assistance text shows inline. For input components, it shows when the field takes focus. In other components it shows all the time. See the user-assistance-density property for other ways the user assistance text can render.

In Alta theme, help.instruction displays in a notewindow when the field takes focus. How is help.instruction better than the html 'title' attribute? The html 'title' attribute only shows up as a tooltip on mouse over, not on keyboard and not in a mobile device. So the html 'title' would only be for text that is not important enough to show all users, or for text that you show the users in another way as well, like in the label. Also you cannot theme the native browser's title window like you can the JET notewindow, so low vision users may have a hard time seeing the 'title' window. For these reasons, the JET EditableValue components do not use the HTML's 'title' attribute and instead use the help.instruction attribute.

To include formatted text in the help.instruction, format the string using html tags. The allowed html tags are: span, b, i, em, br, hr, li, ol, ul, p, small, pre. For example the help.instruction might look like:

<oj-some-element help.instruction="<html>Enter <b>at least</b> 6 characters</html>"></oj-some-element>
If you use formatted text, it should be accessible and make sense to the user if formatting wasn't there.

Default Value:
  • ""
Since:
  • 4.0.0
Names
Item Name
Property help.instruction

help-hints :Object

The helpHints object contains a definition property and a source property.

  • definition - hint for help definition text.
  • source - hint for help source URL.
Since:
  • 4.1.0
Names
Item Name
Property helpHints
Property change event helpHintsChanged
Property change listener attribute (must be of type function, see Events and Listeners for additional information.) on-help-hints-changed

(nullable) help-hints.definition :string

A type of user assistance text. User assistance text is used to provide guidance to help the user understand what data to enter or select. help-hints could come from a help system.

In the Redwood theme for clarity only one user assistance text shows to the user. The precedence rules are:

  • help.instruction shows;
  • if no help.instruction, then validator hint shows;
  • if no help.instruction or validator hint, then help-hints.definition shows;
  • if no help.instruction, validator hint, or help-hints.definition, then converter hint shows.
  • help-hints.source always shows along side the above.

In the Redwood theme, by default all user assistance text shows inline. For input components, it shows when the field takes focus. In other components it shows all the time. See the user-assistance-density property for other ways the user assistance text can render.

In the Alta theme the help-hint.definition shows up when the user hovers over the help icon on the label, or tabs into the help icon, or press and holds the help icon on a mobile device.

No formatted text is available for help definition attribute.

See the help-hints attribute for usage examples.

Default Value:
  • ""
Since:
  • 4.1.0
Names
Item Name
Property helpHints.definition

(nullable) help-hints.source :string

Help source URL associated with the component.

In the Redwood theme, the help-hints.source will show as a link inline to the field. For input components, it shows when the field takes focus. For other components, it shows all the time.

In the Alta theme, the help-hints.source will show as a a help icon next to the label. When clicked the page will navigate to the source url.

For security reasons we only support urls with protocol 'http:' or 'https:'. If the url doesn't comply we ignore it and throw an error. Pass in an encoded URL since we do not encode the URL.

See the help-hints attribute for usage examples.

Default Value:
  • ""
Since:
  • 4.1.0
Names
Item Name
Property helpHints.source

label-edge :('inside'|'none'|'provided')

Specifies how the label of the component is created when the label-hint attribute is set on the component.

The default value varies by theme, and it works well for the theme in most cases. If the component is in an oj-form-layout, the label-edge attribute could come from the oj-form-layout's label-edge attribute. The oj-form-layout component uses the MetadataTypes.PropertyBinding provide property to provide and uses the MetadataTypes.ProvideProperty transform property to transform its label-edge attribute to any descendent components that are configured to consume it. For example, if the oj-form-layout's label-edge attribute is set to "top" or "start", and a descendent form component does not have its label-edge attribute set, the form component's label-edge will be the transformed value "provided".

Supported Values:
Value Description
inside The component creates the label using the label-hint attribute.

For text input components (such as oj-input-text), the label floats over the input element but moves up on focus or when the component has a value.

For non-text input components (such as oj-checkboxset), the label is created at the top of the component and doesn't move.

none The component will not have a label, regardless of whether it's in an oj-form-layout or not.

If the component has a label-hint attribute but no labelled-by, aria-label, or aria-labelledby attribute, the label-hint value will be used as the aria-label.

Note that if the component already has an external label, "none" should not be specified and "provided" should be used instead. Otherwise it may end up with conflicting label information.

provided Label is provided by the parent if the parent is an oj-form-layout.

oj-form-layout provides the label using the label-hint from the form control and the label-edge from oj-form-layout.

If there is no oj-form-layout, use an oj-label.

Since:
  • 8.0.0
Names
Item Name
Property labelEdge
Property change event labelEdgeChanged
Property change listener attribute (must be of type function, see Events and Listeners for additional information.) on-label-edge-changed

label-hint :string

Represents a hint for rendering a label on the component.

This is used in combination with the label-edge attribute to control how the label should be rendered.

When label-edge is "provided", it gives a hint to oj-form-layout parent element to create an oj-label element for the component. When the label-hint attribute changes, oj-form-layout element refreshes to display the updated label information.

When label-edge is "inside", it gives a hint to the component itself to render a label.

When label-edge is "none", and if the component has no labelled-by, aria-label, or aria-labelledby attribute, the label-hint value will be used as the aria-label.

Default Value:
  • ""
Since:
  • 4.1.0
Names
Item Name
Property labelHint
Property change event labelHintChanged
Property change listener attribute (must be of type function, see Events and Listeners for additional information.) on-label-hint-changed

labelled-by :string|null

The oj-label sets the labelledBy property programmatically on the form component to make it easy for the form component to find its oj-label component (a document.getElementById call.)

The application developer should use the 'for'/'id api to link the oj-label with the form component; the 'for' on the oj-label to point to the 'id' on the input form component. This is the most performant way for the oj-label to find its form component.

Default Value:
  • null
Since:
  • 7.0.0
Names
Item Name
Property labelledBy
Property change event labelledByChanged
Property change listener attribute (must be of type function, see Events and Listeners for additional information.) on-labelled-by-changed

messages-custom :Array<oj.Message>

List of messages an app would add to the component when it has business/custom validation errors that it wants the component to show. This allows the app to perform further validation before sending data to the server. When this option is set the message shows to the user right away. To clear the custom message, set messagesCustom back to an empty array.

Each message in the array is an object that duck types oj.Message. See Message for details. message detail text can include formatted HTML text, whereas hints and message summary text cannot. If you use formatted text, it should be accessible and make sense to the user if formatting wasn't there. The allowed html tags are: span, b, i, em, br, hr, li, ol, ul, p, small, pre. To format the message detail, you could do this:

<html>Enter <b>at least</b> 6 characters</html>

See the Validation and Messages section for details on when the component clears messagesCustom; for example, when full validation is run.

In the Redwood theme, the Message summary is not displayed to the user, so make sure to have a Message detail set in your Message object.

Default Value:
  • []
Supports writeback:
  • true
Since:
  • 0.7.0
Names
Item Name
Property messagesCustom
Property change event messagesCustomChanged
Property change listener attribute (must be of type function, see Events and Listeners for additional information.) on-messages-custom-changed

readonly :boolean

Whether the component is readonly. The readOnly property sets or returns whether an element is readOnly, or not. A readOnly element cannot be modified. However, a user can tab to it, highlight it, focus on it, and copy the text from it. If you want to prevent the user from interacting with the element, use the disabled property instead. The element's readOnly property is used as its initial value if it exists, when the attribute is not explicitly set. When neither is set, readOnly defaults to false.

The default value for readonly is false. However, if the form component is a descendent of oj-form-layout, the default value for readonly could come from the oj-form-layout component's readonly attribute. The oj-form-layout uses the MetadataTypes.PropertyBinding provide property to provide its readonly attribute value to be consumed by descendent components. The form components are configured to consume the readonly property if an ancestor provides it and it is not explicitly set. For example, if the oj-form-layout's readonly attribute is set to true, and a descendent form component does not have its readonly attribute set, the form component's readonly will be true.

Default Value:
  • false
Names
Item Name
Property readonly
Property change event readonlyChanged
Property change listener attribute (must be of type function, see Events and Listeners for additional information.) on-readonly-changed

translations :object|null

A collection of translated resources from the translation bundle, or null if this component has no resources. Resources may be accessed and overridden individually or collectively, as seen in the examples.

If the component does not contain any translatable resource, the default value of this attribute will be null. If not, an object containing all resources relevant to the component.

If this component has translations, their documentation immediately follows this doc entry.

Names
Item Name
Property translations
Property change event translationsChanged
Property change listener attribute (must be of type function, see Events and Listeners for additional information.) on-translations-changed

translations.switch-off :string

Text to be displayed when the oj-switch is in readonly mode and value is false.

Default Value:
  • "Off"
Since:
  • 11.0.0
Names
Item Name
Property translations.switchOff

translations.switch-on :string

Text to be displayed when the oj-switch is in readonly mode and value is true.

Default Value:
  • "On"
Since:
  • 11.0.0
Names
Item Name
Property translations.switchOn

user-assistance-density :('reflow'|'efficient'|'compact')

Note: This attribute is not supported in the following themes: Alta

Specifies the density of the form component's user assistance presentation. It can be shown inline with reserved rows to prevent reflow if a user assistance text shows up, inline without reserved rows that would reflow if a user assistance text shows up, or it can be shown compactly in a popup instead.

The default value is 'reflow' when the form component is not a descendent of an oj-form-layout component. When the form component is a descendent of an oj-form-layout, the default value comes from the oj-form-layout's user-assistance-density attribute value.

The oj-form-layout component uses the MetadataTypes.PropertyBinding provide property to provide its user-assistance-density attribute value to be consumed by descendent components. The form components are configured to consume the user-assistance-density property if an ancestor provides it and it is not explicitly set on the form component. Example, oj-form-layout defaults user-assistance-density='efficient', so all its form components descendents will have user-assistance-density='efficient' by default.

Supported Values:
Value Description
compact Messages, help, hints, and required will not be shown inline; they will show in a mode that keeps the screen more compact, like a popup for the messages, and a required icon to indicate Required.
efficient Messages, help, hints, and required are all shown inline under the field with reserved space.
reflow Messages, help, hints, and required are all shown inline under the field with no reserved space.
Default Value:
  • "reflow"
Since:
  • 9.0.0
Names
Item Name
Property userAssistanceDensity
Property change event userAssistanceDensityChanged
Property change listener attribute (must be of type function, see Events and Listeners for additional information.) on-user-assistance-density-changed

(readonly) valid :"valid"|"pending"|"invalidHidden"|"invalidShown"

The current valid state of the component. It is evaluated on initial render. It is re-evaluated

  • after each validator (validators or async-validators) is run (full or deferred)
  • when messagesCustom is updated, since messagesCustom can be added by the app developer any time.
  • when showMessages() is called. Since showMessages() moves the hidden messages into messages shown, if the valid state was "invalidHidden" then it would become "invalidShown".
  • when the required property has changed. If a component is empty and has required set, the valid state may be "invalidHidden" (if no invalid messages are being shown as well). If required property is removed, the valid state would change to "valid".

Note: New valid states may be added to the list of valid values in future releases. Any new values will start with "invalid" if it is an invalid state, "pending" if it is pending state, and "valid" if it is a valid state.

Supported Values:
Value Description
invalidHidden The component has invalid messages hidden and no invalid messages showing. An invalid message is one with severity "error" or higher.
invalidShown The component has invalid messages showing. An invalid message is one with severity "error" or higher.
pending The component is waiting for the validation state to be determined. The "pending" state is set at the start of the convert/validate process.
valid The component is valid
Supports writeback:
  • true
Since:
  • 4.2.0
Names
Item Name
Property valid
Property change event validChanged
Property change listener attribute (must be of type function, see Events and Listeners for additional information.) on-valid-changed

value :boolean

The boolean state of the switch component.
Default Value:
  • false
Supports writeback:
  • true
Names
Item Name
Property value
Property change event valueChanged
Property change listener attribute (must be of type function, see Events and Listeners for additional information.) on-value-changed

Events

ojAnimateEnd

Triggered when a default animation has ended.
Deprecated:
Since Description
12.1.0 This web component no longer supports this event.
Properties:

All of the event payloads listed below can be found under event.detail. See Events and Listeners for additional information.

Name Type Description
action string The action that triggered the animation.

Supported values are:
  • "inline-open" - when an inline message container opens or increases in size
  • "inline-close" - when an inline message container closes or decreases in size
  • "notewindow-open" - when a note window opens
  • "notewindow-close" - when a note window closes
element Element The element being animated.
Since:
  • 12.1.0

ojAnimateStart

Triggered when a default animation is about to start on an element owned by the component.

The default animation can be cancelled by calling event.preventDefault, followed by a call to event.detail.endCallback. event.detail.endCallback should be called immediately after event.preventDefault if the application merely wants to cancel animation, or it should be called when the custom animation ends if the application is invoking another animation function. Failure to call event.detail.endCallback may prevent the component from working properly.

For more information on customizing animations, see the documentation of AnimationUtils.

The default animations are controlled via the theme:

// default animations for notewindow help and hints and messages
$popupTailOpenAnimation: (effect: "zoomIn", transformOrigin: "#myPosition") !default;
$popupTailCloseAnimation: (effect: "none") !default;

// default animations for Redwood's inline messages shown when userAssistanceDensity
// is reflow or efficient.
$messageComponentInlineOpenAnimation: (effect: "fadeIn", duration: "100ms", timingFunction: "linear") !default;
$messageComponentInlineCloseAnimation: (effect: "fadeOut", duration: "100ms", timingFunction: "linear") !default;

// default animations for Alta's "inline" display option
$messageComponentInlineOpenAnimation: (effect: "expand", startMaxHeight: "#oldHeight") !default;
$messageComponentInlineCloseAnimation: (effect: "collapse", endMaxHeight: "#newHeight") !default;
Deprecated:
Since Description
12.1.0 This web component no longer supports this event.
Properties:

All of the event payloads listed below can be found under event.detail. See Events and Listeners for additional information.

Name Type Description
action string The action that triggers the animation.

Supported values are:
  • "inline-hints-open" - when an inline helphints container opens
  • "inline-hints-close" - when an inline helphints container closes
  • "inline-open" - when an inline message container opens or increases in size
  • "inline-close" - when an inline message container closes or decreases in size
  • "notewindow-open" - when a note window opens
  • "notewindow-close" - when a note window closes
element Element The element being animated.
endCallback function():void If the event listener calls event.preventDefault to cancel the default animation, it must call the endCallback function when it finishes its own animation handling and any custom animation has ended.
Since:
  • 12.1.0

Methods

getProperty(property) : {any}

Retrieves the value of a property or a subproperty. The return type will be the same as the type of the property as specified in this API document. If the method is invoked with an incorrect property/subproperty name, it returns undefined.
Parameters:
Name Type Description
property string The property name to get. Supports dot notation for subproperty access.
Since:
  • 4.0.0
Returns:
Type
any
Example

Get a single subproperty of a complex property:

let subpropValue = myComponent.getProperty('complexProperty.subProperty1.subProperty2');

refresh : {void}

Called when the DOM underneath the component changes requiring a re-render of the component. An example is when the id for the input changes.

Another time when refresh might be called is when the locale for the page changes. When it changes, attributes used by its converter and validator that are locale specific, its hints, messages and translations will be updated.

When refresh method is called, the component may take various steps such as clearing messages, running validation etc., based on the state it is in.

Steps Performed Always

  • The converter and validators used by the component are reset, and new converter and validator hints is pushed to messaging. E.g., notewindow displays the new hint(s).

Running Validation

  • if component is valid when refresh() is called, the display value is refreshed if component has a converter set.
  • if component is invalid and is showing messages when refresh() is called, then all component messages are cleared and full validation run using the display value on the component.
    • if there are validation errors, then value attribute is not updated and the error is shown.
    • if no errors result from the validation, the value attribute is updated; page author can listen to the valueChanged event to clear custom errors.
  • if component is invalid and has deferred messages when refresh() is called, then all component messages are cleared and deferred validation is run.

Clearing Messages

  • If clearing messages only those created by the component are cleared.
  • messagesCustom attribute is not cleared.

Since:
  • 0.7.0
Returns:
Type
void

reset : {void}

Resets the component by clearing all messages and messages attributes - messagesCustom - and updates the component's display value using the attribute value. User entered values will be erased when this method is called.
Since:
  • 0.7.0
Returns:
Type
void

setProperties(properties) : {void}

Performs a batch set of properties. The type of value for each property being set must match the type of the property as specified in this API document.
Parameters:
Name Type Description
properties Object An object containing the property and value pairs to set.
Since:
  • 4.0.0
Returns:
Type
void
Example

Set a batch of properties:

myComponent.setProperties({"prop1": "value1", "prop2.subprop": "value2", "prop3": "value3"});

setProperty(property, value) : {void}

Sets a property or a subproperty (of a complex property) and notifies the component of the change, triggering a [property]Changed event. The value should be of the same type as the type of the attribute mentioned in this API document.
Parameters:
Name Type Description
property string The property name to set. Supports dot notation for subproperty access.
value any The new value to set the property to.
Since:
  • 4.0.0
Returns:
Type
void
Example

Set a single subproperty of a complex property:

myComponent.setProperty('complexProperty.subProperty1.subProperty2', "someValue");

showMessages : {void}

Takes all deferred messages and shows them. It then updates the valid property; e.g., if the valid state was "invalidHidden" before showMessages(), the valid state will become "invalidShown" after showMessages().

If there were no deferred messages this method simply returns.

Since:
  • 0.7.0
Returns:
Type
void