Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SAPUI5: how to make select field read-only

Tags:

sapui5

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.

like image 396
keshet Avatar asked Oct 02 '14 20:10

keshet


1 Answers

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.

like image 170
mjd Avatar answered Jan 02 '23 11:01

mjd