/** * Enable or disable automatic, visible validation. * * If automatic validation is enabled, any validators connected to this * component are evaluated while painting the component and potential error * messages are sent to client. If the automatic validation is turned off, * isValid() and validate() methods still work, but one must show the * validation in their own code. * * @param validateAutomatically * True, if automatic validation is enabled. * @return this (for method chaining) * @see AbstractField#setValidationVisible(boolean) */ public default S withValidationVisible(boolean validateAutomatically) { ((AbstractField<T>) this).setValidationVisible(validateAutomatically); return (S) this; }
@Override public void showValidation(boolean isVisible) { isValidationVisible = isVisible; // validation count should already up-to-date, since #showValidation should always occur after #isValid/#validate for (Component c : tabSheet) { if (c instanceof MagnoliaFormTab) { ((MagnoliaFormTab) c).setValidationVisible(isVisible); } } // set validation visibility for all form fields (the Vaadin way) for (FormSection section : getFormSections()) { for (Component component : section) { if (component instanceof AbstractField) { ((AbstractField) component).setValidationVisible(isVisible); } } } }
@Override public void valueChange(Property.ValueChangeEvent event) { if (event != null) { Property property = event.getProperty(); if (property instanceof Field) { Field<?> abstractField = (Field<?>) property; Object propertyId = getPropertyId(abstractField); if (propertyId != null) { boolean wasHiddenValidation = fieldsWithInitiallyDisabledValidation. remove(propertyId.toString()); if (wasHiddenValidation) { if (abstractField instanceof AbstractField) { AbstractField<?> abstractField1 = (AbstractField<?>) abstractField; abstractField1.setValidationVisible(true); } } } else { Logger.getLogger(getClass().getName()).warning( "Property id for field was not found."); } } } setBeanModified(true); if (listener != null) { listener.onFieldGroupChange(this); } }
/** * This method hides validation errors on a required fields until the field * has been changed for the first time. Does pretty much the same as old * Vaadin Form did with its validationVisibleOnCommit, but eagerly per * field. * <p> * Fields that hide validation errors this way are available in * getFieldsWithIntiallyDisabledValidation() so they can be emphasized in * UI. */ public void hideInitialEmpyFieldValidationErrors() { fieldsWithInitiallyDisabledValidation.clear(); for (Field<?> f : getFields()) { if (f instanceof AbstractField) { final AbstractField<?> abstractField = (AbstractField<?>) f; if (abstractField.getErrorMessage() != null && abstractField. isRequired() && abstractField. isEmpty() && abstractField.isValidationVisible()) { final String propertyId = getPropertyId(abstractField). toString(); abstractField.setValidationVisible(false); fieldsWithInitiallyDisabledValidation.add(propertyId); } } } }
@Override public void setPersisted(ET v, boolean persisted) { int row = itemsIdentityIndexOf(v) + 1; if (isAllowRemovingItems()) { Button c = (Button) layout.getComponent(layout.getColumns() - 1, row); if (persisted) { c.setDescription(getDeleteElementDescription()); } else { for (int i = 0; i < getVisibleProperties().size(); i++) { try { AbstractField f = (AbstractField) (Field) layout. getComponent(i, row); f.setValidationVisible(false); } catch (Exception e) { } } c.setDescription(getDisabledDeleteElementDescription()); } c.setEnabled(persisted); } }