Jquery 在表单提交时隐藏下拉列表
我正在使用中包含的指令 所以,发生在我身上的事情,特别是在连接速度较慢的情况下,我在搜索输入框中键入一些东西。。。已触发“提前键入”。。然后我按回车键或点击提交。。。表格提交了。。。但typeahead的下拉列表显示的是任何方式!非常烦人,因为我在提交表单后隐藏了搜索表单,而下拉列表只是漂浮在那里 值得一提的是,将下拉菜单附加到身体时会发生这种情况Jquery 在表单提交时隐藏下拉列表,jquery,angularjs,angular-ui-bootstrap,angular-ui-typeahead,Jquery,Angularjs,Angular Ui Bootstrap,Angular Ui Typeahead,我正在使用中包含的指令 所以,发生在我身上的事情,特别是在连接速度较慢的情况下,我在搜索输入框中键入一些东西。。。已触发“提前键入”。。然后我按回车键或点击提交。。。表格提交了。。。但typeahead的下拉列表显示的是任何方式!非常烦人,因为我在提交表单后隐藏了搜索表单,而下拉列表只是漂浮在那里 值得一提的是,将下拉菜单附加到身体时会发生这种情况 <form ng-submit="Ctrl.onSubmit()"> <input id="fld-pag
<form ng-submit="Ctrl.onSubmit()">
<input
id="fld-page-search"
class="form-control input-lg"
type="search"
data-ng-model="Ctrl.searchTerm"
placeholder="Search by ...."
required
data-ng-minlength="2"
data-typeahead="item.name for item in Ctrl.typeahead($viewValue)"
data-typeahead-min-length="2"
data-typeahead-append-to-body="true"
data-typeahead-on-select="Ctrl.openFund($item)"
data-typeahead-focus-first="false"
data-typeahead-template-url="/static/tpl/fund-discovery-typeahead.html"
>
这确实起到了作用,但当我再次打开/扩展搜索框并尝试再次使用搜索输入typeahead时,列表一直隐藏着,我发现了一个丑陋的解决方案,它似乎在工作,但我肯定不喜欢它
$typeaheadList.hide();
$searchInput.one('keyup', function(){
$typeaheadList.show();
});
我发现没有纯Jquery的工作解决方案很糟糕。 所以,当我需要关闭tupeahead时,您可以简单地从typeahead输入中释放焦点,然后将其返回。我使用以下代码:
//this is close for typeahead control
$timeout(function () {
angular.element(element[0].querySelector('.glyphicon-refresh')).click();
});
//here is server call, or other action
$timeout(function () {
angular.element(element[0].querySelector('input[type=text]')).select();
});
我将这段代码放在cusom指令中,该指令将角度ui类型提前包装。希望这会有所帮助。你把AngularJS和jQuery混为一谈了,这是你的做法,基本上是一个灾难的配方。这就是为什么我这么说,它很难看,我不喜欢它。我想要正确的、有角度的方式。@RobinvanBaalen:我正在做var form=$scope.pageSearchForm;提交表格$SET;在我的控制器中,但是typeahead根本没有得到它,仍然在执行它拥有的队列。。。即使我处理并提交了表单,也会显示弹出窗口。
//this is close for typeahead control
$timeout(function () {
angular.element(element[0].querySelector('.glyphicon-refresh')).click();
});
//here is server call, or other action
$timeout(function () {
angular.element(element[0].querySelector('input[type=text]')).select();
});