Sap.m.Select: start with an empty select input element

When using data aggregation sap.m.Select, the first record is always selected. Here is a link to preview the SDK .

Sample code from my application

new sap.m.Select("id-names", {
    width: '100%',
}).bindAggregation("items", "data>/trip/names", new sap.ui.core.Item({
    text: "{data>Name}"
}));

There is a parameter in the constructor selectedKeyto change it to another index. I want the choice to be empty , because I want to force my users to make a choice, and not accept the first entry in the list.

I can force an empty entry in my aggregation data>/trip/names, but that could pollute my list.

Is there a better way to achieve this?

+4
source share
4 answers

. , . GitHub.

+3

OpenUI5 1.34 forceSelection false.

forceSelection , . - true ( , , ).

false?

, .

https://github.com/SAP/openui5/commit/b2191fd50e2115f8f9d2db7604a75fb50c57591f

+8

, , , forceSelection = false, onInit ( Select):

        var codeField = this.getView().byId("codeField");
        setTimeout(function() {
            codeField.insertItem(new sap.ui.core.ListItem({text: '', key: undefined}), 0);
        }, 1000);

If forceSelection = false is not specified, the field will be loaded too soon or too late for the drop-down list, which will lead to the fact that the wrong choice will be visible. Hope this helps someone.

+1
source

You can also expand the control and create your own selection, for example. an additional parameter adds an empty choice ... I actually think about it too ...

0
source

All Articles