Click here to Skip to main content
15,888,303 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

Is it possible to disable JQuery UI accordion headers in JQ UI 1.8 , so i cant open them? For example i have step 1 till step 4. And i can only open step 2 if i saved step 1.
JavaScript
$(function() {
    var icons = {
           header: "h3",
           activeHeader: "ui-icon-circle-arrow-s"
    };
       $( "#prod_accordion" ).accordion({
           active:<?php echo $db_obj->getValue('status') ? 'acc_'.$tab_status : 'acc_0'; ?>,
           icons: icons,
           autoHeight: false,
           change: function(event, ui) {
               var newIndex = $(ui.newHeader).index('h3');
               if (jQuery.inArray(newIndex , accordion_array) == -1) {
                   var oldIndex = $(ui.oldHeader).index('h3');
                   $(this).accordion('activate' , oldIndex);
               }
           }

       });
   });
Posted
Updated 29-Nov-12 20:10pm
v2
Comments
Sk. Tajbir 21-Nov-12 10:17am    
Can you share your code ?
Ed Nutting 21-Nov-12 11:20am    
Yes. Now work out how :)

You didn't indicate that you had actually tried to solve this yourself, so you shouldn't be expecting anything more than a "yes" or "no" answer...

Ed
T0mii 21-Nov-12 11:22am    
ofc i post it tomorrow in the morning no problem. :)
T0mii 22-Nov-12 3:53am    
[Moved by OP to the question — SA]
Sergey Alexandrovich Kryukov 28-Nov-12 18:02pm    
Could you move it to your question where you can format it properly with HTML tag "pre"? Use Improve question...
--SA

1 solution

I found a way and i thought ill share it hopefully it will help some one else a lot. :)

JavaScript
$(function() {
    var icons = {
           header: "h3",
           activeHeader: "ui-icon-circle-arrow-s"
    };
       $( "#prod_accordion" ).accordion({
           active:<?php echo $db_obj-?>getValue('status') ? 'acc_'.$tab_status : 'acc_0'; ?>,
           icons: icons,
           autoHeight: false,
           beforeActivate: function(event, ui) {
               var newIndex = $(ui.newHeader).index('h3');
               if (jQuery.inArray(newIndex , accordion_array) == -1) {
                   event.preventDefault();
               }
           }

       });
   });


the accrodion_array is an array with indexes like (1,2,3,4) and i check if the index of the clicked accordion lets say 5 is in the array. If not then perventDefault() and the accordion header wont open.

if u add
PHP
ui.addClass('ui-state-disabled');
to the accordion headers that are not in the array the user will now what accordion he cant open. :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900