简体   繁体   中英

How to handle space in YUI autocomplete

I am using YUI 2 autocomplete , I have my own web service which provides suggestions.
Whenever user enters " " (space) then suggestions were not displayed. Like if user enters " foo bar " then suggestion are displayed till " foo " but once user enters " " then suggestion are not displayed.
I checked the Ajax calls and observed that space is replaced by " %20 ". So after space each Ajax call contains " %20 " and that's why no records are retrieved from database.
I tried setting space as delimiter.If we use space as delimiter then it will show suggestions for new term (which user typed after space). Like if you enter " foo bar " then after space it will show suggestion for " bar " while I want suggestions for complete " foo bar " term.
I want to display suggestion for complete term whatever user had typed including space.
Is there any way to handle this in YUI ?

Encoded URL by overriding generateRequest method and it worked :)

myAutoComp.generateRequest = function(sQuery) {
    return "myProject/index.php?query=" + encodeURIComponent(sQuery);
};
YUI().use('autocomplete', 'autocomplete-highlighters', function (Y) {
   Y.one('#ac-input').plug(Y.Plugin.AutoComplete, {
      resultHighlighter: 'phraseMatch',
      source: 'your url'
    });
});

It works fine for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM