SAPUI5 SearchField无法输入但联想功能正常的问题求助
Hey there! Let's figure out why your SearchField won't let you type even though the suggestion dropdown works perfectly. Looking at your code, here are the most likely culprits and fixes:
1. The liveChange Handler Is Clearing Input Immediately
Your handleOrderChange method calls _resetOrderData() every time the input changes. If _resetOrderData resets the Ordernr field (the one bound to your SearchField's value), this means every character you type gets erased right away.
Fix: Update handleOrderChange to only reset data when the input is empty:
handleOrderChange: function (oEvent) { var sCurrentValue = oEvent.getParameter("value"); // Only reset if the input is cleared if (!sCurrentValue || sCurrentValue.trim().length === 0) { this._resetOrderData(); } }
Double-check what _resetOrderData does—if it includes setting Ordernr to an empty string, this adjustment will stop it from interfering with user input.
2. Value Binding Might Be Unidirectional or Bound to a Read-Only Field
Your SearchField uses value="{Ordernr}". If your model is an ODataModel, it defaults to one-way binding by default. While this shouldn't block input outright, if the Ordernr field is marked as read-only in your OData service metadata, the control might be automatically disabled for input.
Fix: Explicitly set two-way binding for the value (if you need user input to sync back to the model) and verify the field's editability in your service:
<SearchField id="orderSearchField" value="{path: 'Ordernr', mode: 'TwoWay'}" placeholder="Vertragsnummer suchen..." enableSuggestions="true" search="onSearch" suggest="handleSuggest" showSearchButton="false" suggestionItems="{ path: '/OrderSet', length: 10, sorter: { path: 'Ordernr' } }" liveChange="handleOrderChange"> <suggestionItems> <SuggestionItem text="{Ordernr}" description="{Name1} {Name2}" key="{Ordernr}"/> </suggestionItems> </SearchField>
3. Quick Sanity Checks
- Make sure no other code is setting
enabled="false"on the SearchField dynamically (suggestions working makes this unlikely, but worth ruling out). - In your
handleSuggestmethod, confirm thatoSearchField.data("prop")is correctly set to"Ordernr"—if this is missing or incorrect, it won't break input, but it's good to verify your filter logic is working as intended.
Let me know if adjusting these fixes your issue!
内容的提问来源于stack exchange,提问作者cecslucas

