Element: <oj-label>

Oracle® JavaScript Extension Toolkit (JET)
5.0.0

E90577-01

QuickNav

Attributes

JET Custom Elements

JET components are implemented as custom HTML elements. In addition to the component attributes documented in this page, JET components also support standard HTML global attributes like id and aria-label.

The JET data binding syntax can be used to define both component and global attributes through the use of dynamically evaluated expressions. All attributes (component and global) support attribute-level binding by prefixing the attribute name with ":" (e.g. :id="[...]"). When using attribute-level binding, all expression values are treated as strings. Additionally, component attributes support property-level binding by using the attribute name directly with no ":" prefix. When using property-level binding, the expressions should evaluate to the types documented by the corresponding attributes. Property-level binding is strongly recommended over attribute-level binding for component attributes.

A detailed description of working with custom HTML elements can be found in: JET Custom Element Usage.


PREVIEW: This is a preview API. Preview APIs are production quality, but can be changed on a major version without a deprecation path.

Version:
  • 5.0.0
Since:
  • 4.0.0
Module:
  • ojlabel

The oj-label component decorates the label text with a required icon and help icon. The user can interact with the help icon (on hover, on focus, etc) to display help description text or to navigate to an url for more help information.

For accessibility reasons, you need to associate the oj-label component to its JET form component. For most JET form components you do this using the oj-label's for attribute and the JET form component's id attribute. For a few JET form components (oj-radioset, oj-checkboxset, oj-color-palette, and oj-color-spectrum) you associate the oj-label component to its JET form component using the oj-label's id attribute and the JET form component's labelled-by attribute. For more examples, see the label demos which show all the JET form controls with oj-label or refer to the JET form component's API jsdoc.


<oj-label for="inputtextid" show-required="[[isRequired]]" 
help.definition="[[helpDef]]" help.source="[[helpSource]]">input label</oj-label>
<oj-input-text id="inputtextid" required="[[isRequired]]"><//oj-input-text>

<oj-label id="radiosetlabel" show-required="[[isRequired]]">radioset</oj-label>
<oj-radioset required="[[isRequired]]" labelled-by="radiosetlabel">
  <oj-option name="color" value="red">Red</oj-option>
  <oj-option name="color" value="blue">Blue</oj-option>
</oj-radioset>

<!--  You can bind the text as a child comment node or on a span element, but not on the 
oj-label element. The knockout text binding is not supported on a JET custom element; -->
<oj-label for="input2"><!--ko text: input2Label --><!--/ko--></oj-label>

Touch End User Information

Target Gesture Action
Help Icon Tap and Hold Show the help definition in a popup
Tap If no help source, show the help definition in a popup. If help source, navigate to the url.

Keyboard End User Information

Target Key Action
Help Icon Enter If there is an url associated with help icon, navigate to the url.
Tab In Show the help definition in a popup.

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.

Slots

JET elements can have up to two types of child content:

  • Any child element with a slot attribute will be moved into that named slot, e.g. <span slot='startIcon'>...</span>. All supported named slots are documented below. Child elements with unsupported named slots will be removed from the DOM.
  • Any child element lacking a slot attribute will be moved to the default slot, also known as a regular child.

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 and demos 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.

Example

Initialize the component with a context menu:

<oj-some-element>
    <-- use the contextMenu slot to designate this as the context menu for this component -->
    <oj-menu slot="contextMenu" style="display:none" aria-label="Some element's context menu">
...
    </oj-menu>
</oj-some-element>

Attributes

for :string|null

The for attribute refers to the id of the element this oj-label element is associated with. Some JET form components support using oj-label's for attribute to point to its id attribute (e.g., oj-input-text, oj-slider), and others do not (e.g., oj-checkboxset).

For the oj-radioset, oj-checkboxset, oj-color-palette, and oj-color-spectrum components, instead of the for attribute, use the id attribute on oj-label with JET's form element's labelled-by attribute.

Refer to the JET's form element's documentation/demos for more examples showing the use of for/id and the use of id/labelled-by.

Default Value:
  • null
Since:
  • 4.0.0
Names
Item Name
Property for
Property change event forChanged
Property change listener attribute (must be of type function) on-for-changed
Example

Associate oj-label to the oj-input-text using the for attribute on oj-label and the id attribute on oj-input-text during initialization.

<oj-label for="inputId">Name:</oj-label>
<oj-input-text id="inputId"></oj-input-text>

help :Object.<string, string>|null

The help information that goes on the oj-label. The help attributes are:
  • definition - this is the help definition text. It is what shows up when the user hovers over the help icon, 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.
  • source - this is the help source url. If present, a help icon will render next to the label. 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.
Properties:
Name Type Argument Description
definition string | null <optional>
help definition text
source string | null <optional>
help source url
Default Value:
  • {'definition' :null, 'source': null}
Since:
  • 4.0.0
Names
Item Name
Property help
Property change event helpChanged
Property change listener attribute (must be of type function) on-help-changed
Examples

Initialize the label with the help definition and help source:

<!-- Using dot notation -->
<oj-label help.definition="some help definition" help.source="some external url">Name:</oj-label>
<!-- Using JSON notation -->
<oj-label help='{"definition":"some value", "source":"someurl"}'>Name:</oj-label>

Set the help attribute, after initialization:

// Set one, leaving the others intact. Use the setProperty API for 
// subproperties so that a property change event is fired.
myComponent.setProperty('help.definition', 'some new value');
// Get all
var values = myComponent.help;
// Set all.  Must list every key, as those not listed are lost.
myComponent.help = {
  definition: 'some new value',
  source: 'some new url'
};

label-id :string|null

label-id sets the id attribute on the internal label element. The use case where this may be needed is if you are using a <div aria-labelledby> and for accessibility reasons you need to point to the oj-label's label element. This should be a corner case. Most often you'd use oj-label's for attribute to associate with a form component's id attribute or use oj-label's id attribute to associate with a JET form component's labelled-by attribute.
Default Value:
  • null
Since:
  • 4.0.0
Names
Item Name
Property labelId
Property change event labelIdChanged
Property change listener attribute (must be of type function) on-label-id-changed
Examples

Initialize the label with the label-id attribute:

<oj-label label-id="labelId">Name:</oj-label>

Set the attribute, after initialization:

// getter
var labelid = myOjLabel.labelId;
// setter
myOjLabel.labelId = "myLabelId";

(nullable) show-required :boolean

Whether this label should have a required icon. It is recommended that you bind the show-required attribute to the same binding as the required attribute on the associated JET form component to make sure they are in sync.
Default Value:
  • false
Since:
  • 4.0.0
Names
Item Name
Property showRequired
Property change event showRequiredChanged
Property change listener attribute (must be of type function) on-show-required-changed
Examples

Initialize the oj-label with the show-required attribute, binding form component's required attribute to the same value.

<oj-label show-required="[[isRequired]]">Name:</oj-label>
<oj-input-text required="[[isRequired]]"></oj-input-text>

Set the attribute, after initialization:

// getter
var showRequired = myOjLabel.showRequired;
// setter
myOjLabel.showRequired = false;

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) on-translations-changed
Examples

Initialize the component, overriding some translated resources and leaving the others intact:

<!-- Using dot notation -->
<oj-some-element translations.some-key='some value' translations.some-other-key='some other value'></oj-some-element>

<!-- Using JSON notation -->
<oj-some-element translations='{"someKey":"some value", "someOtherKey":"some other value"}'></oj-some-element>

Get or set the translations property after initialization:

// Get one
var value = myComponent.translations.someKey;

// Set one, leaving the others intact. Always use the setProperty API for 
// subproperties rather than setting a subproperty directly.
myComponent.setProperty('translations.someKey', 'some value');

// Get all
var values = myComponent.translations;

// Set all.  Must list every resource key, as those not listed are lost.
myComponent.translations = {
    someKey: 'some value',
    someOtherKey: 'some other value'
};

(nullable) translations.tooltip-help :string

Used for the default help icon tooltip.. Most likely the application developer would use the oj-label's help.definition property to specify the help definition text per oj-label element.

Default Value:
  • "Help"
Since:
  • 4.0.0
Names
Item Name
Property translations.tooltipHelp

(nullable) translations.tooltip-required :string

Used for the default required icon tooltip.

Default Value:
  • "Required"
Since:
  • 4.0.0
Names
Item Name
Property translations.tooltipRequired

Methods

getProperty(property) → {*}

Retrieves a value for a property or a single subproperty for complex properties.
Parameters:
Name Type Description
property string The property name to get. Supports dot notation for subproperty access.
Since:
  • 4.0.0
Returns:
Type
*
Example

Get a single subproperty of a complex property:

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

refresh() → {void}

Refreshes the component with all the current attributes.

Call refresh if the id changes, though changing the id shouldn't be needed.

Also, call refresh after required or help changes. The locale could have changed in the meantime, and refresh is needed to update the required and help tooltips.

There should be no need to call refresh for other attribute changes.
Returns:
Type
void
Example
document.getElementById("label1").setProperty("id","label2");
document.getElementById("label2").refresh();

setProperties(properties) → {void}

Performs a batch set of properties.
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 single subproperty for complex properties and notifies the component of the change, triggering a [property]Changed event.
Parameters:
Name Type Description
property string The property name to set. Supports dot notation for subproperty access.
value * 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");