In JSF 2.0 have the following: Using this as a base
<h:inputText id="email" size="60" label="Email"
styleClass=" #{component.valid ? '' : 'input-error'}"
value="#{familyBacking.family.email}" requiredMessage="Required">
<f:validateRequired />
<f:attribute name="family" value="#{familyBacking.family}" />
<f:validator validatorId="EmailValidator" />
<f:validator validatorId="ExistingEmailAddressValidator" />
<f:ajax event="blur" onevent="updateFocus"
render="email emailMessage" />
</h:inputText>
With a javascript function
function updateFocus(obj) {
jQuery(":input.input-error:first").focus();
}
This has the effect to focus and highlight the invalid field. However, it also allows the person to tab to the next input field. So, the sequence is:
- User enters no or invalid data into the field clicks on another field or tab.
- The brower focuses on another field
- The on blur on the original field fires causing the ajax.
- The invalidation occurs, and the class is added to the input. The JS function is executed bringing focus back to the invalid field. All is good until this point.
- BUT, now the onBlur on the 2nd field fires and causes the whole thing again.
Potential Solution:
I can see that the onevent function for the <f:ajax/> is called 3 times. Onces for begin, once for success and once for complete. What I am thinking I can do is somehow disable on blur events for all other input fields until I re-enable them in the last execution of my javascript event.
Suggestions on how I might be able to accomplish this?