Example usage for com.vaadin.client.ui.aria AriaHelper handleInputInvalid

List of usage examples for com.vaadin.client.ui.aria AriaHelper handleInputInvalid

Introduction

In this page you can find the example usage for com.vaadin.client.ui.aria AriaHelper handleInputInvalid.

Prototype

public static void handleInputInvalid(Element element, boolean invalid) 

Source Link

Document

Handles the required actions depending of the input element contains unaccepted input.

Usage

From source file:com.haulmont.cuba.web.toolkit.ui.client.caption.CubaCaptionWidget.java

License:Apache License

@Override
public boolean updateCaption() {
    ComponentConnector owner = getOwner();

    /* CAUTION copied from super class with small changes */
    boolean wasPlacedAfterComponent = placedAfterComponent;

    // Caption is placed after component unless there is some part which
    // moves it above.
    placedAfterComponent = captionPlacedAfterComponentByDefault;

    String style = CLASSNAME;/*  w  w  w.j  a v a2 s . c  o m*/
    if (ComponentStateUtil.hasStyles(owner.getState())) {
        for (String customStyle : owner.getState().styles) {
            style += " " + CLASSNAME + "-" + customStyle;
        }
    }
    if (!owner.isEnabled()) {
        style += " " + StyleConstants.DISABLED;
    }
    setStyleName(style);

    boolean hasIcon = owner.getState().resources.containsKey(ComponentConstants.ICON_RESOURCE);
    boolean showRequired = false;
    boolean showError = owner.getState().errorMessage != null;
    if (owner.getState() instanceof AbstractFieldState) {
        AbstractFieldState abstractFieldState = (AbstractFieldState) owner.getState();
        showError = showError && !abstractFieldState.hideErrors;
    }
    if (owner instanceof AbstractFieldConnector) {
        showRequired = ((AbstractFieldConnector) owner).isRequired();
    }

    if (icon != null) {
        getElement().removeChild(icon.getElement());
        icon = null;
    }
    if (hasIcon) {
        String uri = owner.getState().resources.get(ComponentConstants.ICON_RESOURCE).getURL();

        icon = getOwner().getConnection().getIcon(uri);

        if (icon instanceof ImageIcon) {
            // onload will set appropriate size later
            icon.setWidth("0");
            icon.setHeight("0");
        }

        DOM.insertChild(getElement(), icon.getElement(), getInsertPosition(InsertPosition.ICON));

        // Icon forces the caption to be above the component
        placedAfterComponent = false;
    }

    if (owner.getState().caption != null) {
        // A caption text should be shown if the attribute is set
        // If the caption is null the ATTRIBUTE_CAPTION should not be set to
        // avoid ending up here.

        if (captionText == null) {
            captionText = DOM.createDiv();
            captionText.setClassName("v-captiontext");

            DOM.insertChild(getElement(), captionText, getInsertPosition(InsertPosition.CAPTION));
        }

        // Update caption text
        String c = owner.getState().caption;
        // A text forces the caption to be above the component.
        placedAfterComponent = false;
        if (c == null || c.trim().equals("")) {
            // Not sure if c even can be null. Should not.

            // This is required to ensure that the caption uses space in all
            // browsers when it is set to the empty string. If there is an
            // icon, error indicator or required indicator they will ensure
            // that space is reserved.
            if (!hasIcon && !showRequired && !showError) {
                captionText.setInnerHTML(" ");
            }
        } else {
            setCaptionText(captionText, owner.getState());
        }

    } else if (captionText != null) {
        // Remove existing
        getElement().removeChild(captionText);
        captionText = null;
    }

    if (ComponentStateUtil.hasDescription(owner.getState()) && captionText != null) {
        addStyleDependentName("hasdescription");
    } else {
        removeStyleDependentName("hasdescription");
    }

    AriaHelper.handleInputRequired(owner.getWidget(), showRequired);

    if (showRequired) {
        if (requiredFieldIndicator == null) {
            requiredFieldIndicator = DOM.createDiv();
            requiredFieldIndicator.setClassName("v-required-field-indicator");
            requiredFieldIndicator.setInnerText("*");

            DOM.insertChild(getElement(), requiredFieldIndicator, getInsertPosition(InsertPosition.REQUIRED));

            // Hide the required indicator from assistive device
            Roles.getTextboxRole().setAriaHiddenState(requiredFieldIndicator, true);
        }
    } else if (requiredFieldIndicator != null) {
        // Remove existing
        requiredFieldIndicator.removeFromParent();
        requiredFieldIndicator = null;
    }

    if (isContextHelpIconEnabled(owner.getState())) {
        if (contextHelpIndicatorElement == null) {
            contextHelpIndicatorElement = DOM.createDiv();
            contextHelpIndicatorElement.setClassName(CONTEXT_HELP_CLASSNAME);

            DOM.insertChild(getElement(), contextHelpIndicatorElement, getContextHelpInsertPosition());

            if (clickHandlerRegistration == null) {
                clickHandlerRegistration = addClickHandler(this);
            }
        }
    } else {
        if (contextHelpIndicatorElement != null) {
            contextHelpIndicatorElement.removeFromParent();
            contextHelpIndicatorElement = null;
        }

        if (clickHandlerRegistration != null) {
            clickHandlerRegistration.removeHandler();
            clickHandlerRegistration = null;
        }
    }

    AriaHelper.handleInputInvalid(owner.getWidget(), showError);

    if (showError) {
        if (errorIndicatorElement == null) {
            errorIndicatorElement = DOM.createDiv();

            errorIndicatorElement.setInnerHTML(" ");
            errorIndicatorElement.setClassName("v-errorindicator");

            DOM.insertChild(getElement(), errorIndicatorElement, getInsertPosition(InsertPosition.ERROR));

            // Hide error indicator from assistive devices
            Roles.getTextboxRole().setAriaHiddenState(errorIndicatorElement, true);
        }
    } else if (errorIndicatorElement != null) {
        // Remove existing
        errorIndicatorElement.removeFromParent();
        errorIndicatorElement = null;
    }

    addStyleName(CLASSNAME);

    if (captionHolder != null) {
        captionHolder.captionUpdated(this);
    }
    return (wasPlacedAfterComponent != placedAfterComponent);
}

From source file:com.haulmont.cuba.web.toolkit.ui.client.orderedactionslayout.CubaOrderedActionsLayoutConnector.java

License:Apache License

@Override
protected void updateCaptionInternal(ComponentConnector child) {
    // CAUTION copied from superclass
    CubaOrderedLayoutSlot slot = (CubaOrderedLayoutSlot) getWidget().getSlot(child.getWidget());

    String caption = child.getState().caption;
    URLReference iconUrl = child.getState().resources.get(ComponentConstants.ICON_RESOURCE);
    String iconUrlString = iconUrl != null ? iconUrl.getURL() : null;
    Icon icon = child.getConnection().getIcon(iconUrlString);

    List<String> styles = child.getState().styles;
    String error = child.getState().errorMessage;
    boolean showError = error != null;
    if (child.getState() instanceof AbstractFieldState) {
        AbstractFieldState abstractFieldState = (AbstractFieldState) child.getState();
        showError = showError && !abstractFieldState.hideErrors;
    }/*from w w w. jav a2 s.  co  m*/
    boolean required = false;
    if (child instanceof AbstractFieldConnector) {
        required = ((AbstractFieldConnector) child).isRequired();
    }
    boolean enabled = child.isEnabled();

    if (slot.hasCaption() && null == caption) {
        slot.setCaptionResizeListener(null);
    }

    // Haulmont API
    boolean contextHelpIconEnabled = isContextHelpIconEnabled(child.getState());

    // Haulmont API
    slot.setCaption(caption, contextHelpIconEnabled, icon, styles, error, showError, required, enabled,
            child.getState().captionAsHtml);

    AriaHelper.handleInputRequired(child.getWidget(), required);
    AriaHelper.handleInputInvalid(child.getWidget(), showError);
    AriaHelper.bindCaption(child.getWidget(), slot.getCaptionElement());

    if (slot.hasCaption()) {
        CaptionPosition pos = slot.getCaptionPosition();
        slot.setCaptionResizeListener(slotCaptionResizeListener);
        if (child.isRelativeHeight() && (pos == CaptionPosition.TOP || pos == CaptionPosition.BOTTOM)) {
            getWidget().updateCaptionOffset(slot.getCaptionElement());
        } else if (child.isRelativeWidth() && (pos == CaptionPosition.LEFT || pos == CaptionPosition.RIGHT)) {
            getWidget().updateCaptionOffset(slot.getCaptionElement());
        }
    }
}

From source file:com.haulmont.cuba.web.widgets.client.caption.CubaCaptionWidget.java

License:Apache License

@Override
public boolean updateCaption() {
    ComponentConnector owner = getOwner();

    // CAUTION copied from super class with small changes
    boolean wasPlacedAfterComponent = placedAfterComponent;

    // Caption is placed after component unless there is some part which
    // moves it above.
    placedAfterComponent = captionPlacedAfterComponentByDefault;

    String style = CLASSNAME;//from  w w  w .j  a  va 2  s.c om
    if (ComponentStateUtil.hasStyles(owner.getState())) {
        for (String customStyle : owner.getState().styles) {
            style += " " + CLASSNAME + "-" + customStyle;
        }
    }
    if (!owner.isEnabled()) {
        style += " " + StyleConstants.DISABLED;
    }
    setStyleName(style);

    boolean hasIcon = owner.getState().resources.containsKey(ComponentConstants.ICON_RESOURCE);
    boolean showRequired = false;
    boolean showError = owner.getState().errorMessage != null;
    if (owner.getState() instanceof AbstractFieldState) {
        AbstractFieldState abstractFieldState = (AbstractFieldState) owner.getState();
        showError = showError && !abstractFieldState.hideErrors;
    }
    if (owner instanceof AbstractFieldConnector) {
        showRequired = ((AbstractFieldConnector) owner).isRequired();
    }

    if (icon != null) {
        getElement().removeChild(icon.getElement());
        icon = null;
    }
    if (hasIcon) {
        String uri = owner.getState().resources.get(ComponentConstants.ICON_RESOURCE).getURL();

        icon = getOwner().getConnection().getIcon(uri);

        if (icon instanceof ImageIcon) {
            // onload will set appropriate size later
            icon.setWidth("0");
            icon.setHeight("0");
        }

        DOM.insertChild(getElement(), icon.getElement(), getInsertPosition(InsertPosition.ICON));

        // Icon forces the caption to be above the component
        placedAfterComponent = false;
    }

    if (owner.getState().caption != null) {
        // A caption text should be shown if the attribute is set
        // If the caption is null the ATTRIBUTE_CAPTION should not be set to
        // avoid ending up here.

        if (captionText == null) {
            captionText = DOM.createDiv();
            captionText.setClassName("v-captiontext");

            DOM.insertChild(getElement(), captionText, getInsertPosition(InsertPosition.CAPTION));
        }

        // Update caption text
        String c = owner.getState().caption;
        // A text forces the caption to be above the component.
        placedAfterComponent = false;
        if (c == null || c.trim().equals("")) {
            // Not sure if c even can be null. Should not.

            // This is required to ensure that the caption uses space in all
            // browsers when it is set to the empty string. If there is an
            // icon, error indicator or required indicator they will ensure
            // that space is reserved.
            if (!hasIcon && !showRequired && !showError) {
                captionText.setInnerHTML("&nbsp;");
            }
        } else {
            setCaptionText(captionText, owner.getState());
        }

    } else if (captionText != null) {
        // Remove existing
        getElement().removeChild(captionText);
        captionText = null;
    }

    if (ComponentStateUtil.hasDescription(owner.getState()) && captionText != null) {
        addStyleDependentName("hasdescription");
    } else {
        removeStyleDependentName("hasdescription");
    }

    AriaHelper.handleInputRequired(owner.getWidget(), showRequired);

    if (showRequired) {
        if (requiredFieldIndicator == null) {
            requiredFieldIndicator = DOM.createDiv();
            requiredFieldIndicator.setClassName("v-required-field-indicator");
            requiredFieldIndicator.setInnerText("*");

            DOM.insertChild(getElement(), requiredFieldIndicator, getInsertPosition(InsertPosition.REQUIRED));

            // Hide the required indicator from assistive device
            Roles.getTextboxRole().setAriaHiddenState(requiredFieldIndicator, true);
        }
    } else if (requiredFieldIndicator != null) {
        // Remove existing
        requiredFieldIndicator.removeFromParent();
        requiredFieldIndicator = null;
    }

    if (isContextHelpIconEnabled(owner.getState())) {
        if (contextHelpIndicatorElement == null) {
            contextHelpIndicatorElement = DOM.createDiv();
            contextHelpIndicatorElement.setClassName(CONTEXT_HELP_CLASSNAME);

            if (hasContextHelpIconListeners(owner.getState())) {
                contextHelpIndicatorElement.addClassName(CONTEXT_HELP_CLICKABLE_CLASSNAME);
            }

            DOM.insertChild(getElement(), contextHelpIndicatorElement, getContextHelpInsertPosition());

            if (clickHandlerRegistration == null) {
                clickHandlerRegistration = addClickHandler(this);
            }
        }
    } else {
        if (contextHelpIndicatorElement != null) {
            contextHelpIndicatorElement.removeFromParent();
            contextHelpIndicatorElement = null;
        }

        if (clickHandlerRegistration != null) {
            clickHandlerRegistration.removeHandler();
            clickHandlerRegistration = null;
        }
    }

    AriaHelper.handleInputInvalid(owner.getWidget(), showError);

    if (showError) {
        if (errorIndicatorElement == null) {
            errorIndicatorElement = DOM.createDiv();

            errorIndicatorElement.setInnerHTML("&nbsp;");
            errorIndicatorElement.setClassName("v-errorindicator");

            DOM.insertChild(getElement(), errorIndicatorElement, getInsertPosition(InsertPosition.ERROR));

            // Hide error indicator from assistive devices
            Roles.getTextboxRole().setAriaHiddenState(errorIndicatorElement, true);
        }
    } else if (errorIndicatorElement != null) {
        // Remove existing
        errorIndicatorElement.removeFromParent();
        errorIndicatorElement = null;
    }

    addStyleName(CLASSNAME);

    if (captionHolder != null) {
        captionHolder.captionUpdated(this);
    }
    return (wasPlacedAfterComponent != placedAfterComponent);
}

From source file:com.haulmont.cuba.web.widgets.client.orderedactionslayout.CubaOrderedActionsLayoutConnector.java

License:Apache License

@Override
protected void updateCaptionInternal(ComponentConnector child) {
    // CAUTION copied from superclass
    CubaOrderedLayoutSlot slot = (CubaOrderedLayoutSlot) getWidget().getSlot(child.getWidget());

    String caption = child.getState().caption;
    URLReference iconUrl = child.getState().resources.get(ComponentConstants.ICON_RESOURCE);
    String iconUrlString = iconUrl != null ? iconUrl.getURL() : null;
    Icon icon = child.getConnection().getIcon(iconUrlString);

    List<String> styles = child.getState().styles;
    String error = child.getState().errorMessage;
    boolean showError = error != null;
    if (child.getState() instanceof AbstractFieldState) {
        AbstractFieldState abstractFieldState = (AbstractFieldState) child.getState();
        // vaadin8 rework
        //            showError = showError && !abstractFieldState.hideErrors;
    }/*from w  ww . j  a v  a2 s. c o m*/
    boolean required = false;
    if (child instanceof AbstractFieldConnector) {
        required = ((AbstractFieldConnector) child).isRequiredIndicatorVisible();
    }
    boolean enabled = child.isEnabled();

    if (slot.hasCaption() && null == caption) {
        slot.setCaptionResizeListener(null);
    }

    // Haulmont API
    boolean contextHelpIconEnabled = isContextHelpIconEnabled(child.getState());

    // Haulmont API
    slot.setCaption(caption, contextHelpIconEnabled, icon, styles, error, showError, required, enabled,
            child.getState().captionAsHtml);

    AriaHelper.handleInputRequired(child.getWidget(), required);
    AriaHelper.handleInputInvalid(child.getWidget(), showError);
    AriaHelper.bindCaption(child.getWidget(), slot.getCaptionElement());

    if (slot.hasCaption()) {
        CaptionPosition pos = slot.getCaptionPosition();
        slot.setCaptionResizeListener(slotCaptionResizeListener);
        if (child.isRelativeHeight() && (pos == CaptionPosition.TOP || pos == CaptionPosition.BOTTOM)) {
            getWidget().updateCaptionOffset(slot.getCaptionElement());
        } else if (child.isRelativeWidth() && (pos == CaptionPosition.LEFT || pos == CaptionPosition.RIGHT)) {
            getWidget().updateCaptionOffset(slot.getCaptionElement());
        }
    }
}