Label For Attribute

From W3C XForms Group Wiki (Public)
Jump to: navigation, search

Introduction

It is sometimes convenient to display a control label somewhere other than with the control, and yet still have control relevance govern the label presentation, and retain the A11Y linkage to the control.

The label attribute 'for' contains an IDRef for a XForms control. When the 'for' attribute exists, the label no longer needs to be a child element of the control itself, but can be located anywhere within the active context of the forms model itself. Thus, in the case

<xf:input id="data" ref="context">
    <xf:label>This is data</xf:label>
</xf:input>

Listing 1. Existing meta-control structure

could also be authored as

<xf:label for="data">This is the label for the data control</xf:label>
 ...
<xf:input id="data" ref="data-context" />

Listing 2. Proposed alternate meta-control structure

The in-scope evaluation context for the label with the @for is its lexical context. For instance, in Listing 3, the <xf:label> has a context of "context1" rather than "context2".

<xf:group ref="context1">
  <xf:label for="data"><xf:output ref="."/></xf:label>
</xf:group>
<xf:input ref="context2" id="data" />

Listing 3. Label with associated output.

If the label is rendered in the content flow, then it will be displayed where it appears within the flow, rather than being rendered at the location of the binding control. As such, metadata controls can serve as headers for content in tables and lists. In the case where the metadata control does not normally have a flow presence (e.g., it appears as a modal dialog), this issue does not apply.

Controls in Repeating Structures

ID resolution for a label/@for and control inside a repeat are governed by the same rules for ID resolution with switch/case inside repeat.

For a label/@for outside a repeat and a control inside a repeat, the following rules apply:

  • If the repeat has no rows then there are no controls shown and therefore no labels will show.
  • If the repeat has any rows then there are controls shown and therefore the label will show.
  • If focus is given to the label then the control in the current repeat row is given focus. (Resolution for ids as in switch/case inside repeat should apply.)

If you don't want this effect, use span or some other presentational element which is unconditionally presented.

Labels outside the context of the control

Example:

  <xf:label for="name-input">Name: </xf:label>
  <xf:group ref="/path/to/place">
    <xf:input ref="/other/name" id="name-input" />
  </xf:group>

If the group is not relevant, the input is not shown and therefore the label is not shown.

Extending to help/hint/alert

Extend the @for binding apply to the five primary metadata controls: <xforms:label>, <xforms:hint>, <xforms:help>, <xforms:alert> and <xforms:message>, with the intent that such controls could be placed in a common area and bound to controls by reference rather than being inline to the controls themselves.

Erik Bruchez reports that Orbeon extends this to help, hint, and alert.

Currently awaiting second implementation.

References

This issue was discussed at the following meetings:

May 20th 2011 Meeting

1+ Email Response from T.V. Raman on this issue

[Implementation Report from Erik Bruchez]

[Editorial Meeting]


User:Lklotz