jsfomnifaces

jsf highlight label for invalid input


Is there a simple possibility to apply a specific style to input labels that are invalid?

I've seen omnifaces highlight component which does the job for the input itself, but the given styleguide for my project, forces this for the label of the input.

Something like this would be great:

<h:outputLabel for="inputId" value="label" />
<h:inputText id="inputId" value="..." />

<o:highlight errorLabelStyle="errorLabel" />

Solution

  • This was not possible with <o:highlight>. It's however relatively simple to apply the same style class for the labels as well, so it has been implemented. As per OmniFaces 1.2, you can use it as follows:

    <h:outputLabel for="inputId" value="label" />
    <h:inputText id="inputId" value="..." />
    
    <o:highlight />
    

    with the following CSS:

    label.error {
        color: red;
    }
    
    input.error, select.error, textarea.error {
        background: pink;
    }
    

    The default stlye class name of error is overrideable the usual way:

    <o:highlight styleClass="invalid" />