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?Answer1:
Your question is a little vague, but I guess that you want to enable browser-level form field autocomplete. Something like in this question: <a href="https://stackoverflow.com/questions/16444496/make-text-input-fields-remember-previously-entered-data" rel="nofollow">Make text input fields remember previously entered data</a>.
The main catch is that the browser saves information regarding to field values under these conditions:<ul><li>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).</li> <li>The containing form is submitted.</li> </ul>
Generally, you don't submit forms in UI5, because this is a non-AJAX way of passing data. You can look at this question: <a href="https://stackoverflow.com/questions/15462991/trigger-autocomplete-without-submitting-a-form" rel="nofollow">Trigger autocomplete without submitting a form</a> 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.Answer2:
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 : <a href="https://developer.mozilla.org/en-US/docs/Web/API/History_API" rel="nofollow">https://developer.mozilla.org/en-US/docs/Web/API/History_API</a>
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: <a href="https://sapui5.hana.ondemand.com/explored.html#/sample/sap.m.sample.InputSuggestionsCustomFilter/preview" rel="nofollow">https://sapui5.hana.ondemand.com/explored.html#/sample/sap.m.sample.InputSuggestionsCustomFilter/preview</a>Answer3: