首页 > 解决方案 > aria-autocomplete / typeahead 不是自动选择

问题描述

我已经实现了 aria-autocomplete 和 twitter/bloodhound typeahead。

问题:它在检索值的意义上部分工作,但我希望它被自动选择。当我输入会员 ID 时,我希望它在下面的 div 和隐藏的文本框中自动选择名称(稍后检查是否有值,然后允许用户转到下一个屏幕)

我尝试过的内容: 我已阅读以下内容:

https://msdn.microsoft.com/en-us/ie/hh968240(v=vs.94) https://www.w3.org/TR/wai-aria-practices/examples/combobox/aria1.1pattern/ listbox-combo.html

然后我将“aria-autocomplete”:“list”更改为“both”和“inline”,但都没有影响。

然后,我将文本框从自动完成关闭更改为自动完成,但没有任何效果:

然后我阅读了关于 typeahead 的内容,但我不明白为什么自动完成也没有影响。这是代码:

.

displayKey: function (item) { return item.Subscriber_ID },
            templates: {
                //Template to show if there are no results
                empty: function (context) {
                    //  console.log(1) // put here your code when result not found
                    $(".tt-dataset").text('No Results Found');
                },
                suggestion: function (item) {
                    return '<div class=""> ' + item.First_Name + " " + item.Last_Name + '</div>';
                }
            }
        })

.

标签: asp.netjquery-uiautocompletetypeahead.jsbloodhound

解决方案


我通过向建议函数添加一些代码来解决此问题,以添加 c# 应该查看的 TextBox,而不是在单击后查看它:

 $('#suggestionName').val(item.First_Name + " " + item.Last_Name);        //used to check whether there is a value when hitting submit (hidden field)      
                $('#divDisplayMemberName').html(item.First_Name + " " + item.Last_Name); //displays it in a <p> tag underneath the TextBox
                return '<div class=""> ' + item.First_Name + " " + item.Last_Name + '</div>'; //displays the actual suggestion

推荐阅读