Focus behavior

When a page is loaded, set the initial focus to the specified field or the first field in the tab order of the page.

When a page loads, the behavior sets the focus to the specified field. Without this behavior, browsers usually set initial focus to the "URL" field in the toolbar.

If a field is specified, focus is given to that field. Otherwise, focus is set to the first field in the page's tab order.

JSF tags that emit the component

<hx:inputHelperSetFocus>

Base HTML

Use with <body> only.

JavaScript constructor

hX_5.addBehavior("#body", "onload", new hX_5.JSFBehaviorFocus(attributes)); where

attributes

Comma separated list of attributes where each attribute is a quoted string consisting of the attribute name and value separated by a colon, for example "label:MyLabel".

Note the use of the special ID #body.

Supported events

Event

Description

onload

The behavior can only be used to specify the initial focus in the page.

Attributes

Attribute name

Description

focus-id

The ID of the field given focus. If omitted, focus is given to the first field in the page's tab order.

select

If True, the field's contents are selected (if selection is possible). Otherwise, the field's content is left unselected unless the browser enforces selection when a field is given focus.

Sequencing

Runs after any other handlers provided for the event.

Does not stop the event.

API calls

Table 1. Focus behavior API calls

API call

Description

object = setAttribute(attribute)

Sets an attribute or changes its value (if it was set previously).

string = getAttribute(attribute-name)

Retrieves the current value of an attribute.

Limitations

Example code

Set focus to the first field in the page's tab order. Select the contents.

hX.addBehavior("#body", "onload", new hX.JSFBehaviorFocus("select"));

Set focus to the specified field.

hX.addBehavior("#body", "onload", new hX.JSFBehaviorFocus("focus-id:form1:menu2"));

Feedback