Namespace sap.ui.core.LabelEnablementModule: sap/ui/core/LabelEnablement


Helper functionality for enhancement of a Label with common label functionality.


Since: 1.28.0.
Method Summary
sap.ui.core.LabelEnablement.enrich(oControl)This function should be called on a label control to enrich it's functionality.
sap.ui.core.LabelEnablement.getReferencingLabels(oElement)Returns an array of ids of the labels referencing the given element
sap.ui.core.LabelEnablement.isRequired(oElement)Returns true when the given control is required (property 'required') or one of its referencing labels, false otherwise.
sap.ui.core.LabelEnablement.writeLabelForAttribute(oRenderManager, oLabel)Helper function for the label control to render the html 'for' attribute.
Method Detail
sap.ui.core.LabelEnablement.enrich(oControl)
This function should be called on a label control to enrich it's functionality.

Usage: The function can be called with a control prototype: sap.ui.core.LabelEnablement.enrich(my.Label.prototype); Or the function can be called on instance level in the init function of a label control: my.Label.prototype.init: function(){ sap.ui.core.LabelEnablement.enrich(this); }

Preconditions: The given control must implement the interface sap.ui.core.Label and have an association 'labelFor' with cardinality 0..1. This function extends existing API functions. Ensure not to override this extensions AFTER calling this function.

What does this function do?

A mechanismn is added that ensures that a bidirectional reference between the label and it's labeled control is established: The label references the labeled control via the html 'for' attribute (@see sap.ui.core.LabelEnablement#writeLabelForAttribute). If the labeled control supports the aria-labelledby attribute. A reference to the label is added automatically.

In addition an alternative to apply a for reference without influencing the labelFor association of the API is applied (e.g. used by Form). For this purpose the functions setAlternativeLabelFor and getLabelForRendering are added.

Parameters:
{sap.ui.core.Control}oControl the label control which should be enriched with further label functionality.
Exceptions:
Error if the given control cannot be enriched to violated preconditions (see above)
sap.ui.core.LabelEnablement.getReferencingLabels(oElement): string[]
Returns an array of ids of the labels referencing the given element
Parameters:
{sap.ui.core.Element}oElement The element whose referencing labels should be returned
Returns:
{string[]} an array of ids of the labels referencing the given element
sap.ui.core.LabelEnablement.isRequired(oElement): boolean
Returns true when the given control is required (property 'required') or one of its referencing labels, false otherwise.
Parameters:
{sap.ui.core.Element}oElement The element which should be checked for its required state
Since:
1.29.0
Returns:
{boolean}true when the given control is required (property 'required') or one of its referencing labels, false otherwise
sap.ui.core.LabelEnablement.writeLabelForAttribute(oRenderManager, oLabel)
Helper function for the label control to render the html 'for' attribute. This function should be called at the desired location in the renderer code of the label control.
Parameters:
{sap.ui.core.RenderManager}oRenderManager The RenderManager that can be used for writing to the render-output-buffer.
{sap.ui.core.Label}oLabel The label for which the 'for' html attribute should be written to the render-output-buffer.