You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Entropy <bl...@gmail.com> on 2017/03/10 19:50:17 UTC

Add aria tag and css class to input on error

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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Add aria tag and css class to input on error

Posted by Entropy <bl...@gmail.com>.
That looks pretty darn perfect.  I'll try that.  Thanks!

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Add-aria-tag-and-css-class-to-input-on-error-tp4677286p4677288.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Add aria tag and css class to input on error

Posted by Martin Grigorov <mg...@apache.org>.
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 <bl...@gmail.com> 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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>