[MGNLUI-3748] Impossible to have a select option field with empty value. Created: 15/Jan/16  Updated: 08/Mar/21  Resolved: 08/Mar/21

Status: Closed
Project: Magnolia UI
Component/s: dialogs
Affects Version/s: 5.4.2
Fix Version/s: None

Type: Bug Priority: Neutral
Reporter: Michiel Meeuwissen Assignee: Unassigned
Resolution: Obsolete Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:

 Description   

Sometimes it is more or less logical to have a option in a dropbown box with an empty value. E.g. we used it to indicate 'leave this value empty and inherit it from parent nodes'. But is does not work, and unexpectedly the name of the option is used then.

See
info.magnolia.ui.form.field.factory.SelectFieldFactory


    /**
     * Backward compatibility.
     * If value is null, <br>
     * - get the Name as value.<br>
     * - If Name is empty, set Label as value.
     */
  private String getValue(SelectFieldOptionDefinition option) {
        if (StringUtils.isBlank(option.getValue())) {
            if (StringUtils.isNotBlank(option.getName())) {
                return option.getName();
            } else {
                return getMessage(getLabel(option));
            }
        } else {
            return option.getValue();
        }
    }

The code is also private, so it is hard to change this default somewhat counter intuitive behaviour.

I'm not sure how this facilitates some backwards compatibility. It may do, I'm not sure. I'd sure like an option to switch on/off this.



 Comments   
Comment by Roman Kovařík [ 08/Mar/21 ]

New framework (M6.2) supports comboBox with emptySelectionAllowed property.

https://docs.magnolia-cms.com/product-docs/Templating/Dialog-definition/Field-definition/List-of-fields/Combobox-field.html

Generated at Mon Feb 12 09:09:41 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.