/** * Constructor used by UiBinder. A SubmissionHandler must be set before calling submit. */ public JQMForm() { setStyleName("jqm4gwt-form"); add(generalErrors); }
/** * Adds the given widget and sets it to be required. Then this field will * be checked to ensure it has a value set before the form will be * submitted. In effect, setting a field to required adds an implicit * "not null or empty" validator. */ public void addRequired(JQMFormWidget widget) { addRequired(widget, true); }
/** * see addValidator(null, validator); */ public void addValidator(Validator validator) { addValidator(validator, (JQMFormWidget) null); }
/** * @param immediate - if true then validator will be called during onBlur() event */ public void addRequired(JQMFormWidget widget, String msg, boolean immediate) { add(widget); setRequired(widget, msg, immediate); }
if (la == null) continue; labelAdded = true; addErrorLabel(validator, la); addErrorLabel(validator, label); if (positionErrorAfter == null) { add(label); } else { boolean inserted = false; Widget w = positionErrorAfter; while (w != null) { int i = getWidgetIndex(w); if (i >= 0) { while (i < getWidgetCount()) { Widget wi = getWidget(i); if (wi instanceof Label && JQMCommon.hasStyle(wi, JQM4GWT_ERROR_LABEL_STYLENAME)) { insert(label, i); inserted = true; break; if (!inserted) add(label); registerValidatorWithFiringWidgets(validator, firingWidgets, immediate); boolean required = validator instanceof NotNullOrEmptyValidator; String validatorClass = STYLE_FORM_VALIDATOR + getShortClassName(validator.getClass()); if (notifiedWidget != null) {
remove(label); errors.remove(label); validatorLabels.remove(validator); String validatorClass = STYLE_FORM_VALIDATOR + getShortClassName(validator.getClass()); Widget notifiedWidget = notifiedWidgets.get(validator); if (notifiedWidget != null) { notifiedWidget.getElement().removeClassName(validatorClass); if (required) notifiedWidget.getElement().removeClassName(STYLE_FORM_REQUIRED); removeStyles(validator, notifiedWidget); removeStyles(validator, firingWidget.asWidget());
private void validationStyles(Validator validator, String msg, UIObject ui, boolean pass) { removeStyles(validator, ui); final Label label = validatorLabels.get(validator); if (pass) { // delay cleaning to allow normal button click processing Scheduler.get().scheduleEntry(new ScheduledCommand() { @Override public void execute() { label.setText(null); label.setVisible(false); } }); } else { label.setVisible(true); label.setText(msg); ui.addStyleName(STYLE_ERROR_TYPE + getShortClassName(validator.getClass())); } if (ui.getStyleName().contains(STYLE_ERROR_TYPE)) { ui.addStyleName(STYLE_ERRORCONTAIN); } else { ui.addStyleName(STYLE_OK_VALIDATED); } } }
private static void removeStyles(Validator validator, UIObject ui) { ui.removeStyleName(STYLE_ERROR_TYPE + getShortClassName(validator.getClass())); ui.removeStyleName(STYLE_ERRORCONTAIN); ui.removeStyleName(STYLE_OK_VALIDATED); }
public void clearValidationErrors() { for (Label label : validatorLabels.values()) { label.setVisible(false); } clearValidationStyles(); }
protected void scrollToFirstError() { int y = getFirstErrorOffset(); if (y == 0) return; y -= ERROR_SCROLL_OFFSET; if (y < 0) y = 0; Mobile.silentScroll(y); }
if (la == null) continue; labelAdded = true; addErrorLabel(validator, la, w.asWidget()); addErrorLabel(validator, label, null/*widget*/); add(label); } else { boolean inserted = false; Widget w = positionErrorAfter; while (w != null) { int i = getWidgetIndex(w); if (i >= 0) { while (i < getWidgetCount()) { Widget wi = getWidget(i); if (wi instanceof Label && JQMCommon.hasStyle(wi, JQM4GWT_ERROR_LABEL_STYLENAME)) { insert(label, i); inserted = true; break; addErrorLabel(validator, label, null/*widget*/); add(label); } else { addErrorLabel(validator, label, positionErrorAfter); registerValidatorWithFiringWidgets(validator, firingWidgets, immediate); boolean required = validator instanceof NotNullOrEmptyValidator;
remove(label); errors.remove(label); validatorLabels.remove(validator); String validatorClass = STYLE_FORM_VALIDATOR + getShortClassName(validator.getClass()); Widget notifiedWidget = notifiedWidgets.get(validator); if (notifiedWidget != null) { notifiedWidget.getElement().removeClassName(validatorClass); if (required) notifiedWidget.getElement().removeClassName(STYLE_FORM_REQUIRED); removeStyles(validator, notifiedWidget); removeStyles(validator, firingWidget.asWidget());
/** * @param immediate - if true then validator will be called during onBlur() event */ public void addRequired(JQMFormWidget widget, String msg, boolean immediate) { add(widget); setRequired(widget, msg, immediate); }
private void validationStyles(Validator validator, String msg, UIObject ui, boolean pass) { removeStyles(validator, ui); final Label label = validatorLabels.get(validator); if (pass) { // delay cleaning to allow normal button click processing Scheduler.get().scheduleEntry(new ScheduledCommand() { @Override public void execute() { label.setText(null); label.setVisible(false); } }); } else { label.setVisible(true); label.setText(msg); ui.addStyleName(STYLE_ERROR_TYPE + getShortClassName(validator.getClass())); } if (ui.getStyleName().contains(STYLE_ERROR_TYPE)) { ui.addStyleName(STYLE_ERRORCONTAIN); } else { ui.addStyleName(STYLE_OK_VALIDATED); } } }
private static void removeStyles(Validator validator, UIObject ui) { ui.removeStyleName(STYLE_ERROR_TYPE + getShortClassName(validator.getClass())); ui.removeStyleName(STYLE_ERRORCONTAIN); ui.removeStyleName(STYLE_OK_VALIDATED); }
public void clearValidationErrors() { for (Label label : validatorLabels.values()) { label.setVisible(false); } clearValidationStyles(); }
protected void scrollToFirstError() { int y = getFirstErrorOffset(); if (y == 0) return; y -= ERROR_SCROLL_OFFSET; if (y < 0) y = 0; Mobile.silentScroll(y); }
if (la == null) continue; labelAdded = true; addErrorLabel(validator, la); addErrorLabel(validator, label); if (positionErrorAfter == null) { add(label); } else { boolean inserted = false; Widget w = positionErrorAfter; while (w != null) { int i = getWidgetIndex(w); if (i >= 0) { while (i < getWidgetCount()) { Widget wi = getWidget(i); if (wi instanceof Label && JQMCommon.hasStyle(wi, JQM4GWT_ERROR_LABEL_STYLENAME)) { insert(label, i); inserted = true; break; if (!inserted) add(label); registerValidatorWithFiringWidgets(validator, firingWidgets, immediate); boolean required = validator instanceof NotNullOrEmptyValidator; String validatorClass = STYLE_FORM_VALIDATOR + getShortClassName(validator.getClass()); if (notifiedWidget != null) {
remove(label); errors.remove(label); validatorLabels.remove(validator); String validatorClass = STYLE_FORM_VALIDATOR + getShortClassName(validator.getClass()); Widget notifiedWidget = notifiedWidgets.get(validator); if (notifiedWidget != null) { notifiedWidget.getElement().removeClassName(validatorClass); if (required) notifiedWidget.getElement().removeClassName(STYLE_FORM_REQUIRED); removeStyles(validator, notifiedWidget); removeStyles(validator, firingWidget.asWidget());
/** * see addValidator(null, validator); */ public void addValidator(Validator validator) { addValidator(validator, (JQMFormWidget) null); }