Skip to content

Commit

Permalink
fix(registrar): selection box preview and edit mode
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
HejdaJakub committed Jun 3, 2022
1 parent ee5e0e1 commit 7f8fadb
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -127,6 +135,16 @@ public Widget getWidget() {
@Override
protected void setValueImpl(String value) {
if (isOnlyPreview()) {
Map<String, String> opts = parseItemOptions();

for (Map.Entry<String, String> 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;
}
Expand All @@ -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() {
Expand Down

0 comments on commit 7f8fadb

Please sign in to comment.