Search code examples
sapui5

Input: getSelectedKey is not a function


I am currently having an error while using sap.m.Input, with the suggestion items when I click on the list of suggestion:

controller

ch: function() {
  var filters = [];
  var TBLot = sap.ui.getCore().byId("idTableLot");
  var item = sap.ui.getCore().byId("prd").getSelectedKey();
  var filterL = new Filter("DCI", FilterOperator.EQ, item.toUpperCase());
  var filterWhs = new Filter("Magasin", FilterOperator.EQ, GlobalWarehouse);
  filters.push(filterL);
  filters.push(filterWhs);
  // ...
},

view

var oItemTemplateP = new sap.ui.core.ListItem({
  key: "{ItemName}",
  additionalText: "{U_CMC_RP_CDC}",
  text: "{ItemName}"
});
new sap.m.Input({
  id: "prd",
  autocomplete: true,
  showSuggestion: true,
  enableSuggestionsHighlighting: true,
  suggestionItems: {
    path: "/itm",
    template: oItemTemplateP
  },
  change: [oController.ch, oController]
});

Screenshot of my error: UI5 ".getSelectedKey is not a function"


Solution

  • You must be using an old version of UI5. The method getSelectedKey was introduced in 1.44. To see which UI5 version the app is running with, press Ctrl+Shift+Left Alt+P.