SAPUI5: how to make select field read-only

keshet picture keshet · Oct 2, 2014 · Viewed 8.5k times · Source

I made a combobox using sap.m library:

var oSelection = new sap.m.ComboBox({
    name:   <name>,
    id:     <id>,
    items: {
        <items here>
        })
    },
});

Now, how do I make this field kind of read only, so when I tap it on mobile, it wouldn't bring up the mobile's keyboard, but it would bring up the selection options? I've tried to use editable: false, but it disables the selection together with keyboard.

Thank you.

Answer

mjd picture mjd · Oct 3, 2014

From what I could find out there's no method that allows such behaviour.

One option, that I personally would not advice, is to access the HTML DOM and disable the input field that composes the sap.m.Combobox component.

Keep in mind that if the development SAPUI5 changes the inner workings of the Combobox component your code could be broken if you update the SAPUI5 libraries.

This being said, to use this option you could do something like:

        oSelection.onAfterRendering = function() {
            if (sap.m.ComboBox.prototype.onAfterRendering) {
              sap.m.ComboBox.prototype.onAfterRendering.apply(this);
            }
            document.getElementById("<id>-inner").disabled=true;
        }

replace the < id>-inner by the correct id given to your component.

This was tested using version 1.22.8 of SAPUI5 development toolkit.