on 08-11-2015 2:36 PM
Dear Experts,
I have created one AutoComplete Object as follows
oCB_SO_LensType = new sap.ui.commons.AutoComplete({
editable: true,
selectedItemId:null,
width: '100%',
tooltip: "Enter a name",
maxPopupItems: 10,
displaySecondaryValues: true,
items:{
path:"/E_MaraSet",
template: new sap.ui.core.ListItem({key: "{Matnr}", text: "{Maktx}", additionalText: "{Matnr}"})
},
valueState : sap.ui.core.ValueState.Error,
change: function(oEvent){
searchItemCode = oEvent.getSource();
if(searchItemCode.getSelectedKey()!=null){//GetVarientCode(searchItemCode.getKey()
oCB_SO_LensType.setValueState(sap.ui.core.ValueState.Success);
GetArticlePrice();
oCB_SO_LensSide.focus();
}else{
oCB_SO_LensType.setValueState(sap.ui.core.ValueState.Error);
oCB_SO_LensType.focus();
}
},
});
and the filter as follows
oCB_SO_LensType.setFilterFunction(function(sValue, oItem){
return (oItem.getText().toUpperCase().search(sValue.toUpperCase())!=-1 || oItem.getAdditionalText().search(sValue)!=-1);
});
on poppuing up the suggestion box if i select it through mouse it is giving me the object of combobox which i am using in change event but if select the suggested item using keyboard its not giving me combobox object it is empty i dont know how to handle this situation and i am stuck in it.
Kindly Advise
Rgards
:S
I don't understand your code... why aren't you using the 'suggest' property of the AutoComplete control?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The 'suggest' event is fired when the suggestion list would show up.
See for examples the 'Dynamic items' and 'Custom filter function' examples on sap.ui.commons.AutoComplete
Hi Muhammad,
Check this link for sample code using suggest event -
Regards,
Sai Vellanki.
Then,see these examples-AutoComplete - SAPUI5 Demo Kit
thanks this was helpful but
when i implemented suggest event like following
suggest: function(oEvent){
var sValue = oEvent.getParameter("suggestValue");
var oFilter1 = isNaN(sValue)
? new sap.ui.model.Filter("Maktx", sap.ui.model.FilterOperator.Contains, sValue)
: new sap.ui.model.Filter("Matnr", sap.ui.model.FilterOperator.EQ, sValue);
oCB_SO_LensType.getBinding("/E_MaraSet").filter([oFilter1], sap.ui.model.FilterType.Application);
},
it is giving me
Uncaught TypeError: Cannot read property 'filter' of undefined
Dear Robin
I tried what you suggested that filter exception is not being thrown now but filteration is also not neing done, no Suggestion list is being appeared, it appears only if i start typing whith the starting characters i have also checked one thing that filter method also take 3 arguments
Parameters:
I dont understand the last two parameters also
Regards
Let me take a step back... If I understood you correctly:
In that case, you don't need a model filter, but just the AutoComplete 'setFilterFunction' specified correctly:
var oCB_SO_LensType = new sap.ui.commons.AutoComplete({
displaySecondaryValues: true,
items:{
path:"/E_MaraSet",
template: new sap.ui.core.ListItem({key: "{Matnr}", text: "{Maktx}", additionalText: "{Matnr}"})
},
// I left out most other properties and only show here the most relevant ones for easier reading
});
oCB_SO_LensType.setFilterFunction(function(sValue, oItem) {
var value = sValue.toLowerCase();
if (oItem.getText().toLowerCase().indexOf(value) != -1 ||
oItem.getKey().toLowerCase().indexOf(value) != -1 ||
oItem.getAdditionalText().toLowerCase().indexOf(value) != -1) {
return oItem;
}
});
That is all
Dear Robin
this is what i have done initially but you suggested to implement suggest event, problem with this solution is when i select item by using mouse it gives me the source of combo from which i can select the key of the selected item but if scroll down using keyboard down arrow key within the suggested box and then hit enter then insted of firing its own enterkey event its firing AutoComplete onsapenterkey event which executes before it get the selectedKey() which in turns null object in the key.
Kindly look again on top my firest blog about it you will find the same solution but problem is different.
secondly i thing setFilterFunction should return any boolean value but you are returning oItem is it possible?
regards
:S
Hi,
I guess I wasn't entirely sure what you wanted to achieve with your code from the beginning... the 'suggest' event is indeed fired when the selection list is opened, but I now understand upon changing a value you want something to happen with the selected key, right?
In that case, the 'change' event indeed is the correct one.
I could not reproduce your issue with the keyboard navigation though... See this little example: Edit fiddle - JSFiddle which works just fine with both keyboard and mouse
Dear Robin
I checked your example it is perfect image of my solution, i implemented the same but some how change event is not being fired when i select the item from the suggested list usng keyboard but when i click on it is being fired any idea about it??? and many many special thanks for your time i really appriciate it.
Regards
:S
Dear All
I have found following solution also, kindly check this out
var selObj = oEvent.getSource();
var selCon = selObj.oPopup.oContent;
var selKey = selCon.getSelectedItem().getKey();
in the change method and obtained the reference of the object which is selected by ENTER key. It is working fine for both mouse and Enter
Regards
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.