7

我已经在 YUI 中实现了自动完成功能。但我想做的是,当用户选择一个建议时,表单应该与建议一起提交

<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>

我有这样的形式

<form ...>
    <input name="searchId" id="searchId" placeholder="Search Product" />
     ......
</form>
  1. 自动建议正在正确出现。但是当用户选择建议时,它应该在表单中提交
  2. 还有另一个自动建议框,它实际上会获得与用户输入内容相关的建议,如下所示

在此处输入图像描述

来自 YUI 建议的Orange color文本/类别,我如何显示它们,如图所示。[平板电脑、平板电脑保护套和保护套来自 YUI]

4

1 回答 1

2
Check nout the following code. I have pasted HTML, JavaScript and CSS separately.

HTML 代码

<html>
 <body class="yui3-skin-sam">
   <div class="line">
    <div id="invoice-customer-id">
      <input type="text"  value="x"/>
     </div>
   </div>
  </body>
 </html>

Java 脚本

   YUI().use('node', 'autocomplete', 'autocomplete-highlighters', 'autocomplete-filters', function (Y){
var node = Y.one('input'),
    items = [0,1,2,3,4,5,6,7,8,9,'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'e', 'f'];

node.plug(Y.Plugin.AutoComplete, {
      height: '100px',
      minQueryLength: 0,
      scrollIntoView: true,
      circular: false,
      resultHighlighter: 'phraseMatch',
      resultFilters: 'phraseMatch',
      source: items,
    on : {
    select : function(e) {
        console.log(arguments); //TODO: update your code
    }}
    });
}); // end of javascript

CSS

.line {
 overflow: hidden;
 /* position: relative; */
 }
 .yui3-aclist-content {
   overflow-y: auto;
  }
 #invoice-customer-id {
   padding: 8% 0;
 }
于 2013-12-27T17:32:07.297 回答