Tracks which field within a form had focus before the form was submitted (excluding the button used to submit the form, if any).
The behavior takes no attributes. Instead, it looks for hidden fields within the form that have special names. If the field with the ID form-id:POST_LASTFIELD (where form-id is the ID of the form) is found in the form, then this hidden field is used to transmit the ID of the field that had focus back to the server. If the field with the ID form-id:POST_LASTCURSOR is found in the form, then this hidden field is used to transmit the cursor position within that field back to the server. The cursor position is -1 if the field does not support selection, otherwise it's the zero-based character position in the field that immediately follows the text cursor (e.g., if the zero is returned, the cursor is before the first character in the field).
The behavior tracks focus events that occur within the form (and keydown and mouse events if need be). Browsers do not generate events such as focus, click, etc. when an event is generated directly from Javascript. For example, if a Javascript obj.focus() call is made in a page, no event is generated. In this case, as no event is generated, the behavior will not know if a field has been given focus (or that the cursor has been moved). All hxclient-based component and behaviors will correctly track the focus in this case (as they use a common focus management routine), but any non-hxclient based Javascript will not work correctly if it sets focus (or the cursor). Thus odc-based components may not work correctly (they are not hxclient-based). Custom Javascript on the page may also not work correctly.
None. Behavior is used in iSeries JSF extensions.
Must be attached to a <form> tag.
<input type="hidden" disabled="true" id="form-id:POST_LASTFIELD"> <input type="hidden" disabled="true" id="form-id:POST_LASTCURSOR">
hX_5.addBehavior("id", "oninput", new hX_5.JSFBehaviorTrack()); where
id |
The ID of the HTML tag to which the component is attached. |
Event |
Description |
---|---|
oninput |
Note the use of the special event name. The behavior modifies all keyboard event handlers as well as focus and blur. |
Runs after any other handlers provided for the event. Does not stop the event.
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. |
Set up a form to return the focus/cursor information about the last field within it that had focus.
<form id="form1"> <input type="text" id="form1:text1" /><br> <input type="text" id="form1:text2" /><br> <select id="form1:menu1" name="form0:menu1" class="selectOneMenu" size="1"> <option value="Value0">One</option> <option value="Value1">Two</option> <option value="Value2">Three</option> </select> <input type="submit" value="Submit" id="form01:button1" name="form1:button1" /> <input type="hidden" id="form1:POST_LASTFIELD" /> <input type="hidden" id="form1:POST_LASTCURSOR" /> </form> <script> hX.addBehavior("form1", "oninput", new hX.JSFBehaviorTrack()); hX.onPageLoad(); </script>