diff --git a/src/main/java/org/olat/core/gui/components/form/flexible/elements/TextElement.java b/src/main/java/org/olat/core/gui/components/form/flexible/elements/TextElement.java index 1b76906b6a3c12758df0cbbb920ead8955769835..350ea08680d3c347ca60af654d65c9d71c4fddad 100644 --- a/src/main/java/org/olat/core/gui/components/form/flexible/elements/TextElement.java +++ b/src/main/java/org/olat/core/gui/components/form/flexible/elements/TextElement.java @@ -145,4 +145,11 @@ public interface TextElement extends FormItem{ */ public void setMaxLength(int maxLength); + /** + * Check the visible length of the text (can be used for datas saved in XML file + * but not for DB) + * @param checkVisibleLength + */ + public void setCheckVisibleLength(boolean checkVisibleLength); + } \ No newline at end of file diff --git a/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/AbstractTextElement.java b/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/AbstractTextElement.java index 6e519d3baad1e0e8cfe6ef7a802a0d5fd59de310..afa0e37e605ffd9e81c74539d41a29dc6429e9b2 100644 --- a/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/AbstractTextElement.java +++ b/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/AbstractTextElement.java @@ -75,6 +75,7 @@ public abstract class AbstractTextElement extends FormItemImpl implements TextEl private int notLongerLength; protected int displaySize; protected int maxlength = -1; //default no maxlength restriction + protected boolean checkVisibleLength = false; private String notLongerThanErrorKey; private String checkForOtherValue; private String otherValueErrorKey; @@ -204,7 +205,10 @@ public abstract class AbstractTextElement extends FormItemImpl implements TextEl this.maxlength = maxLength; } - + public void setCheckVisibleLength(boolean checkVisibleLength) { + this.checkVisibleLength = checkVisibleLength; + } + /** * @param errorKey * @return @@ -245,7 +249,11 @@ public abstract class AbstractTextElement extends FormItemImpl implements TextEl private boolean notLongerThan(){ boolean lengthError = false; try { - if (value.length() > notLongerLength || value.getBytes("UTF-8").length > notLongerLength) { + if(checkVisibleLength) { + if (value.length() > notLongerLength) { + lengthError = true; + } + } else if (value.length() > notLongerLength || value.getBytes("UTF-8").length > notLongerLength) { lengthError = true; } } catch (UnsupportedEncodingException e) { diff --git a/src/main/java/org/olat/course/editor/NodeConfigFormController.java b/src/main/java/org/olat/course/editor/NodeConfigFormController.java index a595686356850be24e81a8da94e35fdaf2c79ce8..0ccff3e7d682c15c28bfbbabba018e228a3c0866 100644 --- a/src/main/java/org/olat/course/editor/NodeConfigFormController.java +++ b/src/main/java/org/olat/course/editor/NodeConfigFormController.java @@ -145,6 +145,7 @@ public class NodeConfigFormController extends FormBasicController { // add the short title text input element shortTitle = uifactory.addTextElement("nodeConfigForm.menutitle", "nodeConfigForm.menutitle", SHORT_TITLE_MAX_LENGTH, (menuTitle == null ? "": menuTitle), formLayout); shortTitle.setMandatory(true); + shortTitle.setCheckVisibleLength(true); // add the title input text element title = uifactory.addTextElement("nodeConfigForm.displaytitle", "nodeConfigForm.displaytitle", 255, (displayTitle==null? "": displayTitle), formLayout);