*/
public class AbstractFieldState extends ComponentState {
private boolean propertyReadOnly = false;
+ private boolean hideErrors = false;
/**
* Checks if the property data source for the Field is in read only mode.
this.propertyReadOnly = propertyReadOnly;
}
+ /**
+ * Returns true if the component will hide any errors even if the error
+ * message is set.
+ *
+ * @return true if error messages are disabled
+ */
+ public boolean isHideErrors() {
+ return hideErrors;
+ }
+
+ /**
+ * Sets whether the component should hide any errors even if the error
+ * message is set.
+ *
+ * This is used e.g. on forms to hide error messages for invalid fields
+ * before the first user actions.
+ *
+ * @param hideErrors
+ * true if error messages should be hidden
+ */
+ public void setHideErrors(boolean hideErrors) {
+ this.hideErrors = hideErrors;
+ }
+
}
private int maxWidth = -1;
- protected static final String ATTRIBUTE_CAPTION = "caption";
- protected static final String ATTRIBUTE_DESCRIPTION = "description";
protected static final String ATTRIBUTE_REQUIRED = AbstractComponentConnector.ATTRIBUTE_REQUIRED;
- protected static final String ATTRIBUTE_HIDEERRORS = AbstractComponentConnector.ATTRIBUTE_HIDEERRORS;
private enum InsertPosition {
ICON, CAPTION, REQUIRED, ERROR
boolean hasIcon = owner.getState().getIcon() != null;
boolean showRequired = uidl
.getBooleanAttribute(AbstractComponentConnector.ATTRIBUTE_REQUIRED);
- boolean showError = owner.getState().getErrorMessage() != null
- && !uidl.getBooleanAttribute(AbstractComponentConnector.ATTRIBUTE_HIDEERRORS);
+ boolean showError = owner.getState().getErrorMessage() != null;
+ if (owner.getState() instanceof AbstractFieldState) {
+ showError = showError
+ && !((AbstractFieldState) owner.getState()).isHideErrors();
+ }
if (hasIcon) {
if (icon == null) {
// Not all references to the string literals have been converted to use
// these!
public static final String ATTRIBUTE_REQUIRED = "required";
- public static final String ATTRIBUTE_HIDEERRORS = "hideErrors";
private Widget widget;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.AbstractFieldState;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.BrowserInfo;
import com.vaadin.terminal.gwt.client.ComponentConnector;
public void updateFromUIDL(UIDL uidl, ComponentConnector component) {
owner = component;
- if (null != owner.getState().getErrorMessage()
- && !uidl.getBooleanAttribute(AbstractComponentConnector.ATTRIBUTE_HIDEERRORS)) {
+ boolean showError = null != owner.getState().getErrorMessage();
+ if (owner.getState() instanceof AbstractFieldState) {
+ showError = showError
+ && !((AbstractFieldState) owner.getState())
+ .isHideErrors();
+ }
+ if (showError) {
if (errorIndicatorElement == null) {
errorIndicatorElement = DOM.createDiv();
DOM.setInnerHTML(errorIndicatorElement, " ");
ErrorMessage error = getErrorMessage();
if (null != error) {
sharedState.setErrorMessage(error.getFormattedHtmlMessage());
+ } else {
+ sharedState.setErrorMessage(null);
}
return sharedState;
target.addAttribute(AbstractComponentConnector.ATTRIBUTE_REQUIRED,
true);
}
-
- // Hide the error indicator if needed
- if (shouldHideErrors()) {
- target.addAttribute(
- AbstractComponentConnector.ATTRIBUTE_HIDEERRORS, true);
- }
}
/**
@Override
public AbstractFieldState getState() {
- return (AbstractFieldState) super.getState();
+ AbstractFieldState state = (AbstractFieldState) super.getState();
+
+ // Hide the error indicator if needed
+ state.setHideErrors(shouldHideErrors());
+
+ return state;
}
@Override
currentPage = -1; // current page is always set by client
optionRequest = true;
-
- // Hide the error indicator if needed
- if (shouldHideErrors()) {
- target.addAttribute(
- AbstractComponentConnector.ATTRIBUTE_HIDEERRORS, true);
- }
}
/**