Hi,

Here is a simple Behavior that adds "has-error" CSS class to any component
that has an error feedback message:

public class ErrorBehavior extends Behavior {

    @Override
    public void onComponentTag(Component component, ComponentTag tag) {
        FeedbackCollector feedbackCollector = new
FeedbackCollector(component);
        List<FeedbackMessage> feedbackMessageList =
feedbackCollector.collect(new
ErrorLevelFeedbackMessageFilter(FeedbackMessage.ERROR));
        if (CollectionUtils.isNotEmpty(feedbackMessageList)) {
            tag.append("class", "has-error", " ");
        }
    }
}

You can add it to all FormComponents with IComponentInstantiationListener:

public static class InstantiationListener implements
IComponentInstantiationListener {
@Override
public void onInstantiation(Component component)
{
if (component instanceof FormComponent)
{
component.add(new ErrorBehavior());
}
}
}

In YourApplication#init(): getComponentInstantiationListeners().add(new
InstantiationListener())


Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Fri, Mar 10, 2017 at 8:50 PM, Entropy <[email protected]> wrote:

> We need to add an aria tag to out input controls(and maybe a css class)
> whenever they have an error on that control.  Is there a way to make that
> happen automagically for a whole form, or would each valdator do it or
> what?
> How would one go about that in wicket?
>
> --
> View this message in context: http://apache-wicket.1842946.
> n4.nabble.com/Add-aria-tag-and-css-class-to-input-on-error-tp4677286.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

Reply via email to