@Override protected boolean validateFormLogic(UserRequest ureq) { boolean allOk = true; acknowledgeEl.clearError(); if (!acknowledgeEl.isAtLeastSelected(1)) { acknowledgeEl.setErrorKey("details.read.only.acknowledge.error", null); allOk &= false; } return allOk & super.validateFormLogic(ureq); }
@Override protected boolean validateFormLogic(UserRequest ureq) { boolean allOk = true; if (!isInherit()) { glossarEl.clearError(); if (glossarEl.isAtLeastSelected(1)) { if (!jsOptionEl.isSelected(1)) { allOk &= false; glossarEl.setErrorKey("glossary.need.jQuery", null); } } heightEl.clearError(); if (heightEl.isSelected(0) && (standardModeEl.isSelected(0) || jsOptionEl.isSelected(0))) { heightEl.setErrorKey("automatic.need.js", null); allOk = false; } } return allOk & super.validateFormLogic(ureq); }
/** * @see * org.olat.core.gui.components.form.flexible.impl.FormBasicController#validateFormLogic(org.olat.core.gui.UserRequest) */ @Override public boolean validateFormLogic(UserRequest ureq) { // 1) Check valid group names if (!StringHelper.containsNonWhitespace(businessGroupName.getValue())) { businessGroupName.setErrorKey("form.legende.mandatory", new String[] {}); return false; } if (bulkMode) { // check all names to be valid and check that at least one is entered // e.g. find "," | " , " | ",,," errors => no group entered String selectionAsCsvStr = businessGroupName.getValue(); String[] activeSelection = selectionAsCsvStr != null ? selectionAsCsvStr.split(",") : new String[] {}; validNames = new HashSet<String>(); Set<String> wrongNames = new HashSet<String>(); boolean nameTooLong = false; for (int i = 0; i < activeSelection.length; i++) { String currentName = activeSelection[i].trim(); if (currentName.getBytes().length > BusinessGroup.MAX_GROUP_NAME_LENGTH) { nameTooLong = true; } else if ((currentName).matches(BusinessGroup.VALID_GROUPNAME_REGEXP)) { validNames.add(currentName); } else { wrongNames.add(currentName); } } if (validNames.size() == 0 && wrongNames.size() == 0 && !nameTooLong) { // no valid name and no invalid names, this is no names businessGroupName.setErrorKey("create.form.error.illegalName", new String[] {}); return false; } else if (nameTooLong) { businessGroupName.setErrorKey( "create.form.error.nameTooLong", new String[] {BusinessGroup.MAX_GROUP_NAME_LENGTH + ""}); return false; } else if (wrongNames.size() == 1) { // one invalid name businessGroupName.setErrorKey("create.form.error.illegalName", new String[] {}); return false; } else if (wrongNames.size() > 1) { // two or more invalid names String[] args = new String[] {StringHelper.formatAsCSVString(wrongNames)}; businessGroupName.setErrorKey("create.form.error.illegalNames", args); return false; } } else { String groupName = businessGroupName.getValue(); if (groupName.getBytes().length > BusinessGroup.MAX_GROUP_NAME_LENGTH) { businessGroupName.setErrorKey( "create.form.error.nameTooLong", new String[] {BusinessGroup.MAX_GROUP_NAME_LENGTH + ""}); return false; } else if (!(groupName).matches(BusinessGroup.VALID_GROUPNAME_REGEXP)) { businessGroupName.setErrorKey("create.form.error.illegalName", new String[] {}); return false; } if (businessGroupName.hasError()) { return false; // auto-validations from form, return false, because of that // clearError()-calls everywhere... } } // all group name tests passed businessGroupName.clearError(); // 2) Check valid description if (businessGroupDescription.getValue().length() > 4000) { businessGroupDescription.setErrorKey("input.toolong", new String[] {"4000"}); return false; } businessGroupDescription.clearError(); // 3) Check auto close settings boolean disableWaitingListOk = true; if (businessGroup != null) { int waitingPartipiciantSize = businessGroupService.countMembers(businessGroup, GroupRoles.waiting.name()); if ((businessGroup.getWaitingListEnabled()).booleanValue() && !isWaitingListEnabled() && (waitingPartipiciantSize > 0)) { enableAutoCloseRanks.setErrorKey("form.error.disableNonEmptyWaitingList", new String[] {}); disableWaitingListOk = false; setEnableWaitingList(true); return false; } } enableAutoCloseRanks.clearError(); if (disableWaitingListOk) { // 4) Check min / max settings String maxValue = null; if (StringHelper.containsNonWhitespace(businessGroupMaximumMembers.getValue())) { maxValue = businessGroupMaximumMembers.getValue(); } String minValue = null; if (StringHelper.containsNonWhitespace(businessGroupMinimumMembers.getValue())) { minValue = businessGroupMinimumMembers.getValue(); } if (isWaitingListEnabled() && (maxValue == null || minValue == "")) { enableWaitingList.setErrorKey("create.form.error.enableWaitinglist", new String[] {}); return false; } enableWaitingList.clearError(); // 5) Check auto close - waiting list dependency if (isAutoCloseRanksEnabled() && !isWaitingListEnabled()) { enableAutoCloseRanks.setErrorKey("create.form.error.enableAutoCloseRanks", new String[] {}); return false; } enableAutoCloseRanks.clearError(); // 6) Check min/max validity if (!businessGroupMaximumMembers .getValue() .matches("^\\p{Space}*(\\p{Digit}*)\\p{Space}*$")) { businessGroupMaximumMembers.setErrorKey("create.form.error.numberOrNull", new String[] {}); return false; } if (!businessGroupMinimumMembers .getValue() .matches("^\\p{Space}*(\\p{Digit}*)\\p{Space}*$")) { businessGroupMaximumMembers.setErrorKey("create.form.error.numberOrNull", new String[] {}); return false; } businessGroupMaximumMembers.clearError(); } // group name duplication test passed businessGroupName.clearError(); // all checks passed return true; }