Skip to Content

ComboBox attachChange

Hello everyone,

I am using Combobox in SAPUI5, but recently facing a problem, hope someone can help me!
Based on the documentation an event change is fired when:

  • The focus leaves the text input field
  • The Enter key is pressed
  • In addition, this event is also fired when an item in the list is selected.

Unfortunately the last one is not working in my case. What exactly happens is that when I click with mouse the list is closed and the name is selected correctly, but the cursor is still pulsing so the text input of the ComboBox is still focused.

Here you have my code:

var languageComboBox = new sap.m.ComboBox();
//Add items to languageComboBox: 

for (var i in data.locales){ 

var currentItem = data.locales[i]; 

if (currentItem.enabled) 

languageComboBox.addItem(new sap.ui.core.Item({, text: currentItem.label}));

languageComboBox.attachChange(function(oEvent) {
var oSelectedItem = languageComboBox.getSelectedItem(); 
var sItemKey = oSelectedItem.getKey(); 

var sItemText = oSelectedItem.getText();.........

PS. .attachChange works correctly if there are two other cases happening.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Posted on Oct 16, 2019 at 09:19 AM

    hi Lefter,

    I am not sure whats the issue if the the cursor is still at ComboBox because the control is behaving as expected.

    Correct me if I have misunderstood your issue.

    The documentation never says that the event will remove the focus from the combobox. Hence when you select the value form dropdown, the change event is triggered and the selected entry changes.


    Vaibhav Maheshwari

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Vaibhav,

      thanks for the answer and sorry for my late one.
      sapui version: "1.38.39"

      I have tried that, the attachChange does not get triggered if just click in one of the elements of the list.

      That's how I put the items in the ComboBox.

      data.locales is a vector of objects.

      for (var i in data.locales)
      var currentItem = data.locales[i];
      if (currentItem.enabled)
      languageComboBox.addItem(new sap.ui.core.Item({,text: currentItem.label}));
  • Posted on Oct 16, 2019 at 06:13 PM

    Hi Lefter,

    Could you please try with "attachSelectionChange()" instead of "attachChange()"



    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.