Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    SelectItemCombo setAddUnknownValues allowing a unknown value

    Hi all,

    I'm not if this is a fault or not but I have an issue with a SelectComboItem displaying a value despite setAddUnknowwnValues being set to false.

    I have a DynamicForm which is generated from some configuration.

    The fields are then populated by data I retrieve via an Rpc call.

    So this is my original code

    Code:
        private void setFieldValues(Map<String, String> values) {
            for (FormItem item : formsForm.getFields()) {
                String fieldName = item.getAttribute(CrmFieldFactory.FIELD_NAME);
                if (fieldName != null && values.containsKey(fieldName)) {
                    item.setValue(values.get(fieldName));
                }
            }
        }
    However some of these fields may be SelectItemCombo and have setAddUnknowwnValues(false) and despite the value not being in the valuesMap, still displays that values.

    I have a work around for now

    Code:
        private void setFieldValues(Map<String, String> values) {
            for (FormItem item : formsForm.getFields()) {
                String fieldName = item.getAttribute(CrmFieldFactory.FIELD_NAME);
                if (fieldName != null && values.containsKey(fieldName)) {
                    String value = values.get(fieldName);
                    if (isValueOk(item, value)) {
                        item.setValue(value);
                    }
                }
            }
        }
    
        private boolean isValueOk (FormItem item, String value) {
            if (item instanceof SelectItemCombo) {
                SelectItemCombo selectItem = (SelectItemCombo) item;
                if (!Boolean.TRUE.equals(selectItem.getAddUnknownValues())) {
                    Record valueMap = selectItem.getAttributeAsRecord("valueMap");
                    return valueMap.getAttribute(value) != null;
                }
            }
            return true;
        }
    From the UI point of view, typing an unknown value into the SelectItemCombo box is not accepted.

    So the question is this i guess for weather this is a bug or not, if a SelectItemCombo has addUnknownValues set to false, and I call setValue() passing in a value not in the value map, should it be accepted?

    Thanks,
    Dale
Working...
X