0

I'm trying to make a SAPUI5 Input have live suggestions when the user types.

<Input id="modeloInput" type="Text" maxLength="20" editable="true" required="true"
                                showValueHelp="true" submit="onModeloSubmit" suggest="onSuggest" suggestionItemSelected="handleSuggestionModelo" showSuggestion="true" startSuggestion="3"  suggestionItems="{ModeloVH>/ItemsTableFiltered}" valueHelpRequest="handleModeloValueHelp" 
                            
                                value="{ path: 'SearchModel>/modelo', type: 'sap.ui.model.type.String', constraints: { minLength: 4, maxLength: 20} }" textAlign="End">
                                <layoutData>
                                    <l:GridData span="L4 M4 S4"/>
                                </layoutData>
                            <suggestionItems>
                                <core:Item key="{ModeloVH>Zprodh}" text="{ModeloVH>Zvtext4o}" />
                            </suggestionItems>
</Input>

In my controller:

{
        onSuggest: function (oEvent) {

            var text = that.inputModelo.getValue();
        

        that.getView().getModel("ModeloVH");
            var suggestionModel = that.getModeloHelpModel();


            var items = suggestionModel.getData().ItemsTable;

            var filteredItems = items.filter(item => item.Zvtext40.startsWith(text));
            suggestionModel.setProperty("/ItemsTableFiltered", filteredItems);
            suggestionModel.setProperty("/ItemsTableFiltered",items);

            that.inputModelo.setModel("ModeloVH",suggestionModel);
            that.inputModelo.setModel(suggestionModel, "ModeloVH");
            var bindingSuggestionItems = oEvent.getSource().getBinding('suggestionItems');
            

            that.inputModelo.getModel("ModeloVH").refresh(true);
        }
}

If I look at the suggestionItems binding, it has the results: getBinding("suggestionItems)

the suggestions popup doesn't fire: ui suggestion doesnt show

I get all the data on the onInit method. Can't make the suggestion popup fire.

Any suggestions?

Thanks.

Benedikt Kromer
  • 711
  • 6
  • 22
carmaikol
  • 17
  • 5
  • 1
    thats not how it works, you are supposed to manipulate the filter of the binding. Everything else is done for you https://sapui5.hana.ondemand.com/#/entity/sap.m.Input/sample/sap.m.sample.InputSuggestionsDynamic/code/C.controller.js – Benedikt Kromer Jun 10 '22 at 14:37

1 Answers1

0

As a quickfix, I found that I can add items programmatically:

addItemToSuggestion: function(input, key, text) {

           input.addSuggestionItem( 
                            new sap.m.SuggestionItem({  
                             key: key,     
                              text: text  
                             }) 
           ) 
     },  

On the onSuggest event, iterate through the results list and call the function:

filteredItems.forEach(item =>   that.addItemToSuggestion(that.inputModelo, item.Zprodh, item.Zvtext40));

Hope this helps.

carmaikol
  • 17
  • 5