YUI Auto Complete Suggestion with submission

Viewed 609

I have implemented the Auto Complete feature in YUI. But what I would like to do is, when user selects a suggestion, the form should be submitted along with the suggestion

<script>
    YUI().use('array-extras','autocomplete','autocomplete-highlighters',function(Y) {

        function locateModules(response) {
            var results = [];

            if(response && response.dimensions){
                for (var i = 0; i < response.dimensions.length; i++) {
                    if(response.dimensions[i] && response.dimensions[i].refinements){
                        for (var j = 0; j < response.dimensions[i].refinements.length; j++) {
                            if(response.dimensions[i].refinements[j].refinements){
                                results = results.concat(response.dimensions[i].refinements[j].refinements)
                            }
                            results.push(response.dimensions[i].refinements[j]);
                        }
                    }
                }
            }

            return Y.Array.filter(results, function(result) {
                            //some other conditions
                return true;
            });
        }

        Y.one('#searchId').plug(Y.Plugin.AutoComplete, {
            resultHighlighter : 'phraseMatch',
            resultListLocator : locateModules,
            resultTextLocator : 'name',
            source : '<%=autoCompleteURL%>&<portlet:namespace/>q={query}'
        });
});
</script>

and I have form like this

<form ...>
    <input name="searchId" id="searchId" placeholder="Search Product" />
     ......
</form>
  1. The auto-suggestions are coming properly. But when user selects the suggestion, it should be submitted in the form
  2. There's another auto-suggestion box, which actually gets suggestion related to what users is typing as shown below

enter image description here

The Orange color text/categories coming from YUI suggestion, how do I show them as shown in picture. [Tablets, Tablet Cases & Covers are coming from YUI]

1 Answers
Related