From 7f8fadbddfae62f3df157f588383c9dec5c92816 Mon Sep 17 00:00:00 2001 From: HejdaJakub Date: Tue, 31 May 2022 12:09:38 +0200 Subject: [PATCH] fix(registrar): selection box preview and edit mode * Selection box on preview now displays user friendly labels instead of pure values. * Selection box in the edit mode is now disabled if the item is not updatable. --- .../registrar/widgets/items/Selectionbox.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/perun-wui-registrar/src/main/java/cz/metacentrum/perun/wui/registrar/widgets/items/Selectionbox.java b/perun-wui-registrar/src/main/java/cz/metacentrum/perun/wui/registrar/widgets/items/Selectionbox.java index 418c197f..d9257a8a 100644 --- a/perun-wui-registrar/src/main/java/cz/metacentrum/perun/wui/registrar/widgets/items/Selectionbox.java +++ b/perun-wui-registrar/src/main/java/cz/metacentrum/perun/wui/registrar/widgets/items/Selectionbox.java @@ -33,6 +33,13 @@ public Selectionbox(PerunForm form, ApplicationFormItemData item, String lang) { this.validator = new SelectionboxValidator(); } + @Override + public void setEnabled(boolean enabled) { + if (getSelect() != null) { + getSelect().setEnabled(enabled); + } + } + @Override protected Widget initWidget() { @@ -92,6 +99,7 @@ protected Widget initWidgetOnlyPreview() { widget = new Paragraph(); Icon caret = new Icon(IconType.CARET_DOWN); caret.setPull(Pull.RIGHT); + caret.setColor("#ccc"); getPreview().add(caret); getPreview().addStyleName("form-control"); return widget; @@ -127,6 +135,16 @@ public Widget getWidget() { @Override protected void setValueImpl(String value) { if (isOnlyPreview()) { + Map opts = parseItemOptions(); + + for (Map.Entry entry : opts.entrySet()) { + // value from param is the key in this map (but we want to display the value from map) + if (entry.getKey().equals(value)) { + getPreview().add(new Span(entry.getValue())); + return; + } + } + // if this option was deleted by admin from this form item, then it won't be parsed, and we have to display raw value getPreview().add(new Span(value)); return; } @@ -137,7 +155,9 @@ protected void setValueImpl(String value) { return; } } - getSelect().refresh(); + // set the value which doesn't match any option (this option was probably deleted after the form had been saved) + getSelect().addItem(value, value); + getSelect().setSelectedIndex(getSelect().getItemCount() - 1); } public Select getSelect() {