Skip to content
Snippets Groups Projects
Commit 7bb97d73 authored by gnaegi's avatar gnaegi
Browse files

OO-2934 allow deleting of last tag in textbox, beautify disabled rendering of tabs

parent 586a7982
No related branches found
No related tags found
No related merge requests found
......@@ -76,9 +76,7 @@ public class TextBoxListElementImpl extends AbstractTextElement implements TextB
} else {
//this one handle multipart/form too
String submitValue = getRootForm().getRequestParameter(inputId);
if(StringHelper.containsNonWhitespace(submitValue)) {
component.setCmd(ureq, submitValue);
}
component.setCmd(ureq, submitValue);
}
}
......
......@@ -153,9 +153,10 @@ public abstract class TextBoxListComponent extends FormBaseComponentImpl {
}
public void setCmd(UserRequest ureq, String cmd) {
if(!StringHelper.containsNonWhitespace(cmd)) {
if(cmd == null) {
return;
}
// empty string is ok = empty text box
String[] splitted = cmd.split(",");
List<String> cleanedItemValues = new ArrayList<String>();
......@@ -434,12 +435,13 @@ public abstract class TextBoxListComponent extends FormBaseComponentImpl {
}
/**
* returns a the initialItems as comma-separated list.<br />
* returns a the current items as comma-separated list.<br />
*
* @return An HTML escaped list of item
*/
protected String getInitialItemsAsString() {
Map<String, String> content = getInitialItems();
protected String getItemsAsString() {
Map<String, String> content = getCurrentItems();
if (content != null && content.size() != 0) {
//antisamy + escaping to prevent issue with the javascript code
OWASPAntiSamyXSSFilter filter = new OWASPAntiSamyXSSFilter();
......
......@@ -30,6 +30,8 @@ import org.olat.core.gui.render.Renderer;
import org.olat.core.gui.render.StringOutput;
import org.olat.core.gui.render.URLBuilder;
import org.olat.core.gui.translator.Translator;
import org.olat.core.util.Formatter;
import org.olat.core.util.Util;
/**
* Description:<br>
......@@ -57,7 +59,7 @@ public class TextBoxListRenderer extends DefaultComponentRenderer {
TextBoxListComponent tblComponent = (TextBoxListElementComponent) source;
if (tblComponent.isEnabled()) {
renderEnabledMode(tblComponent, sb);
renderEnabledMode(tblComponent, sb, translator);
} else {
renderDisabledMode(tblComponent, sb);
}
......@@ -72,18 +74,20 @@ public class TextBoxListRenderer extends DefaultComponentRenderer {
* the StringOutput
* @param translator
*/
private void renderEnabledMode(TextBoxListComponent tblComponent, StringOutput sb) {
private void renderEnabledMode(TextBoxListComponent tblComponent, StringOutput sb, Translator translator) {
TextBoxListElementImpl te = ((TextBoxListElementComponent)tblComponent).getTextElementImpl();
Form rootForm = te.getRootForm();
String dispatchId = tblComponent.getFormDispatchId();
String initialValue = tblComponent.getInitialItemsAsString();
String initialValue = tblComponent.getItemsAsString();
sb.append("<input type='text' id='textboxlistinput").append(dispatchId).append("'")
.append(" name='textboxlistinput").append(dispatchId).append("'");
if (te.hasFocus()) {
sb.append(" autofocus");
}
sb.append(" value='").append(initialValue).append("' />\n");
sb.append(" value='").append(initialValue).append("'");
Translator myTrans = Util.createPackageTranslator(this.getClass(), translator.getLocale());
sb.append(" placeholder='").append(Formatter.escapeDoubleQuotes(myTrans.translate("add.enter"))).append("' class='o_textbox'/>\n");
String o_ffEvent = FormJSHelper.getJSFnCallFor(rootForm, dispatchId, 2);
// generate the JS-code for the bootstrap tagsinput
......@@ -116,11 +120,13 @@ public class TextBoxListRenderer extends DefaultComponentRenderer {
private void renderDisabledMode(TextBoxListComponent tblComponent, StringOutput output) {
// read only view, we just display the initialItems as
// comma-separated string
String readOnlyContent = tblComponent.getInitialItemsAsString();
String readOnlyContent = tblComponent.getItemsAsString();
if (readOnlyContent.length() > 0) {
output.append("<div><i class='o_icon o_icon_tags'> </i> ")
.append(readOnlyContent)
.append("</div>");
output.append("<span class='o_textbox_disabled'><i class='o_icon o_icon_tags'> </i> ");
for (String item : readOnlyContent.split(",")) {
output.append("<span class='tag label label-info'>").append(item.trim()).append("</span>");
}
output.append("</span>");
} else {
output.append("-");
}
......
......@@ -2,3 +2,4 @@ add.new.element.prefix=Hinzuf\u00fcgen
please.wait.searching=Bitte warten. Suche nach:
more.results.found.specify.search=Es wurden noch weitere Resultate gefunden, bitte Suche verfeinern.
default.input.hint=Klicken Sie hier, um ein Element hinzuzuf\u00fcgen. Mehrere Elemente k\u00f6nnen mit Komma getrennt werden.
add.enter=Eingabe mit \u23CE abschliessen
\ No newline at end of file
......@@ -3,3 +3,4 @@ add.new.element.prefix=Add
default.input.hint=Click here to add an element. Several elements can be separated by commas.
more.results.found.specify.search=More search results found. Please refine your search.
please.wait.searching=Please be patient. Searching for\:
add.enter=Terminate input with \u23CE
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment