[英]How to open a bootstrap-select menu
I am using bootstrap-select in a form with many entries. 我在具有许多条目的表单中使用引导选择。 Now i would like to validate the form in a way that the user is guided more precisely through the missing fields.
现在,我想以一种方式引导用户通过丢失的字段更准确地验证表单。 so i use:
所以我用:
$('html, body').animate
to scroll to the missing field / select item and then: 滚动到缺少的字段/选择项目,然后:
field.focus();
to set the cursor into an input field 将光标设置在输入字段中
Now for the select items i would like to open the dropdown in that case. 现在,对于选择项,我想在这种情况下打开下拉菜单。
Is there a way to do that? 有没有办法做到这一点?
i was trying the following thanks to tip from muggles: 感谢麻瓜的提示,我尝试了以下操作:
function goToFormField(field){
var offset=80;
$('html, body').animate({
scrollTop: field.parent().offset().top - offset
}, 100,"easeInOutCirc",function(){
if(field.is("input")){
field.focus();
}else if(field.is("select")){
field.selectpicker('show')
}
}
);
}
but it did not work. 但它没有用。 EDIT: the mentioned function selectpicker('show') just shows the select-item, not the dropdown contents.
编辑:提到的函数selectpicker('show')仅显示选择项,而不显示下拉菜单内容。
Thanks. 谢谢。
bootstrap-select only requires an open class to be added in the same class as select element, for example: bootstrap-select只需要在与select元素相同的类中添加一个开放类,例如:
// To Open
$('.selectpicker').addClass('open');
// To Close
$('.selectpicker').removeClass('open');
I am assuming you are talking about this plugin for Bootstrap. 我假设你正在谈论这个插件引导。
If so, according to the documentation , the plugin has a .show() method which programmatically shows the bootstrap select menu. 如果是这样,根据文档 ,该插件具有.show()方法,该方法以编程方式显示引导程序选择菜单。
$('.selectpicker').selectpicker('show');
You can use the following code. 您可以使用以下代码。
setTimeout(function(){
$('#selector_id').next().click();
}, 500);
It will click the toggle dropdown button and will make the dropdown-menu open. 它将单击切换下拉菜单按钮,并将打开下拉菜单。 Just replace "selector_id" with your required id.
只需将“ selector_id”替换为所需的ID。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.