Reputation: 365
I have an input control with suggestions. Whenever a user selects something that matches what he is typing/ if the entered value is random, we need to call an oData service to validate the input. Issue is: if user selects a value and it is different than the previous one - then the service is called twice. This is because both the function is triggered twice. on change() and suggestionItemSelected(). I am calling the same function both the place as essentially same task is to be done.
How to ensure that if the value is indeed changed but selected from suggestions call the function only once?
XML.view
<Input id="cc" change="onCC" showSuggestion="true" suggestionItems="{path:'order>/CreditCard'}"
suggestionItemSelected="onCC">
<suggestionItems>
<core:Item key="{order>CardNumber}" text="{order>CardNumber}"/>
</suggestionItems>
</Input>
Controller.js
onCardSelected: function (oEvent) {
var sServiceUrl = this.getOwnerComponent().getMetadata().getManifestEntry("sap.app").dataSources["abc"].uri;
var OdataModel = new sap.ui.model.odata.v2.ODataModel(sServiceUrl);
var sPath = "/ABCSet";
var oFilters = [];
oFilters.push(new sap.ui.model.Filter("CardNumber", sap.ui.model.FilterOperator.EQ, valueEntered));
OdataModel.read(sPath, {
filters: oFilters,
success: this._ccValidateSuccess.bind(this),
error: this._ccValidateError.bind(this)
});
}
Upvotes: 0
Views: 1337
Reputation: 1044
You do not need an event handler for 'suggestionItemSelected'. Because change event handler is anyway getting triggered even when a suggestionItemSelected.
Upvotes: 1