How to add browser cache autocomplete in SAPUI5 Input field?

荒凉一梦 提交于 2019-12-12 02:26:19

问题


How to add browser cache autocomplete in SAPUI5 Input field?

I have a SAPUI5 form with input fields. I want these input fields to display autocomplete from browser history like any other website. Any idea?


回答1:


Your question is a little vague, but I guess that you want to enable browser-level form field autocomplete. Something like in this question: Make text input fields remember previously entered data.

The main catch is that the browser saves information regarding to field values under these conditions:

  • The input fields have names (you can set the name of an input field via the "name" property of the UI5 sap.m.Input control).
  • The containing form is submitted.

Generally, you don't submit forms in UI5, because this is a non-AJAX way of passing data. You can look at this question: Trigger autocomplete without submitting a form for a solution to this problem.

Alternatively, you can store the values by yourself in e.g. the localStorage and use them to fill up the sap.m.Input's suggestionItems aggregation.




回答2:


I would suggest using the window.history to access the history of your browser. However, window.history does not allow for looking at various URLs for security reasons.

The History API is well documented with examples here : https://developer.mozilla.org/en-US/docs/Web/API/History_API

If however, you can store the URLs that you wish to turn on suggestions for in a model, you can avoid window.history and simple use the suggestion feature of an Input field. A sample of this is provided here: https://sapui5.hana.ondemand.com/explored.html#/sample/sap.m.sample.InputSuggestionsCustomFilter/preview




回答3:


LocalCacheSettings: function(){

            var aSelectedTokens = this.getView().byId("processOrderNo").getTokens();
            var aModelData = [];
            for(var i = 0; i < aSelectedTokens.length ; i++){
                aModelData.push({
                    "key" : i.toString(),
                    "value" : aSelectedTokens[i].getText()
                });
        jQuery.sap.storage(jQuery.sap.storage.Type.local).put("myLocalData", aModelData);


        }
            this.aProcessOrderTyped = [];
            var oLocalCacheModel = new sap.ui.model.json.JSONModel();
            jQuery.sap.require("jquery.sap.storage");
            var oStorage = jQuery.sap.storage(jQuery.sap.storage.Type.local);
            //this.aProcessOrderTyped;
            if(oStorage.get("myLocalData")){
                this.aProcessOrderTyped = oStorage.get("myLocalData");
                oLocalCacheModel.setData(this.aProcessOrderTyped);
            }
            this.getView().setModel(oLocalCacheModel, "POModel");


来源:https://stackoverflow.com/questions/42778647/how-to-add-browser-cache-autocomplete-in-sapui5-input-field

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!