I've got the following markup:
<div id="accordion" class="leftaligned">
<div>
<h3><a href="#">Stakeholder</a></h3>
<div>Content</div>
</div>
<div>
<h3><a href="#">Relationships</a></h3>
<div>Blah blah</div>
</div>
<div>
<h3><a href="#">Address</a></h3>
<div>Yada yada</div>
</div>
<div>
<h3><a href="#">Contact Details</a></h3>
<div>Foo bar</div>
</div>
</div>
I create an accordion as follows:
$("#accordion").accordion({
header: "h3",
fillSpace: true,
changestart: function(event, ui) {
if (someConditionIsTrue()) {
event.stopPropagation();
event.preventDefault();
return (false);
}
}
});
The idea is that there are some use cases which would prevent the user from changing panes, however the above cancelling of the event has no effect and the panes can still be changed.
Is there a way to prevent the changing of panes? I also tried activating the current pane programmatically in order to prevent the change, but that fires another changestart event and all hell breaks loose (the accordion actually breaks)
Assuming you are using the jQuery UI accordion, you can collapse all sections with . accordion('activate', false) . First, in your HTML, give all accordion containers class="accordion" to make them more readily addressable as a group. You can keep the id="accordion1" etc.
You can try the following if you are positive about the position the tab to be disable has: // Disable the first tab $( "#accordion > h3:first-child" ). addClass( "ui-state-disabled" ); // Make sure the fourth tab is enabled $( $( "#accordion > h3" )[3] ). removeClass( "ui-state-disabled" );
Note: Since the activate event is only fired on panel activation, it is not fired for the initial panel when the accordion widget is created. If you need a hook for widget creation use the create event.
Maybe it's available in older jQueryUIs but if you use jQuery-UI 1.9.2 or newer you can disable accordion collapsing in beforeActivate event;
beforeActivate: function (event, ui) {
event.preventDefault();
}
Before initing accordion add your custom click handler with your logic. stopImmediatePropagation will stop event before accordion handler will be called.
$('.quiz-qa h3').click(function(e) {
if ($(this).hasClass("deleted")) {
e.stopImmediatePropagation();
return false;
}
});
$('.quiz-qa').accordion();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With