简体   繁体   English

Bootstrap 3折叠手风琴停止/禁用打开spefifc面板

[英]Bootstrap 3 collapse accordion stop / disable opening spefifc panel

I have a bootstrap 3 accordion I would like to stop X panel from opening if my form is not validated. 我有一个bootstrap 3手风琴,如果我的表单未经验证,我想阻止X面板打开。 I have the following code so far but still can't get it to stop opening 到目前为止,我有以下代码,但仍然无法停止打开

// Accordion 
    $('#accordion').on('shown.bs.collapse', function (e) {
        var id = $(e.target).prev().find("[id]")[0].id;
        var poNumber = s.splice(id, 0, 2);
        if (false === $('#bioForm').parsley().validate('PO' + poNumber-1)) {
           e.stopPropagation(); 
        } else {
            $('body').animate({
                scrollTop: $("#" + id).offset().top
            }, 1000);
        }

    });

Here is the HTML (just the first panel its the same for the rest) 这是HTML(剩下的只是第一个面板)

<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<div class="panel panel-default">
<!-- PO 1 -->
<div class="panel-heading" role="tab" id="heading1">
<a data-toggle="collapse" id="po1" data-parent="#accordion" href="#collapse1" aria-expanded="true" aria-controls="collapse1">
<h4 class="panel-title"> PO #1
</h4>
</a>
</div>
<div id="collapse1" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="heading1">
<div class="panel-body">
<div class="form-group">
</div>
</div>
 </div>
</div>
 <!-- PO 1 END -->

Add a click event to the toggle href. 将点击事件添加到切换href。 We have to assume this fires before the collapse events so the propagation can be stopped. 我们必须在崩溃事件发生之前假设发生这种情况,以便可以停止传播。 See http://jsfiddle.net/xwhes56a/1 参见http://jsfiddle.net/xwhes56a/1

var valid = false;

$(function() {
  $('a[data-toggle]').on('click', function(e) {
    // Panel that is currently open
    var panel = $('div.in');
    if (! valid) {
      alert('Sorry panel ' + panel[0].id + ' not validated');
      e.stopPropagation();
    }
  });
});

How about this: 这个怎么样:

if (false === $('#bioForm').parsley().validate('PO' + poNumber-1)) {
   $(this).collapse();
}

Per the "Via Javascript" Section of the Bootstrap documentation 根据引导文档的“通过Java脚本”部分

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Bootstrap 3手风琴菜单:停止打开面板,同时打开页面 - Bootstrap 3 accordion menu: Stop the panel open from also opening the page Bootstrap折叠手风琴:使用JavaScript打开面板不会关闭其他打开的面板 - Bootstrap Collapse Accordion: Opening a panel by JavaScript does not close other open panels 打开后禁用Bootstrap手风琴 - Disable Bootstrap accordion after opening Bootstrap可折叠面板不会在另一个面板开口上折叠 - Bootstrap collapsible panel to not collapse on another panel opening 停止引导手风琴面板在表单提交时崩溃 - Stop bootstrap accordion panel collapsing on form submit Bootstrap Collapse Accordion一个面板打开,所有其他面板关闭 - Bootstrap Collapse Accordion one panel open, all others close Bootstrap手风琴-折叠时更改顶部面板的位置 - Bootstrap Accordion - change the position of top panel when collapse 如何水平折叠react-bootstrap手风琴面板? - How to collapse react-bootstrap accordion panel horizontally? 如何在面板标题Click事件上扩展/折叠Bootstrap手风琴? - How to expand/collapse bootstrap accordion on panel-heading click event? 在大分辨率下禁用 Bootstrap 3 折叠手风琴中的切换选项 - Disable toggle option in Bootstrap 3 collapse accordion on large resolutions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM