Dazvolt
Dazvolt

Reputation: 697

Jquery ui .sortable() enable-disable

First of all, let me explain my page structure, so you can get the idea how is it working. I've got some number of quick-button blocks. They can be sorted by Jquery ui .sortable() method, but only after pressing settings button (which allows quick buttons to be sortable). Later, order of this buttons could be saved or could be canceled. So I need to look through 3 conditions which are fired up by click event. Problem is, on first time everything is ok, but on second time when I'm trying to press button settings - sortable() method is not working anymore.

You can see my JS below:

    $('#tune-hot-links').click(function () { //Click "settings" button  
            $(".sect-hot-links-inner").sortable();
            $(".sect-hot-links-inner").disableSelection();      
    });
    $('.button-editgroup button.button-save').click(function () {   //Click "save" button       
            $(".sect-hot-links-inner").sortable('disabled');
            $(".sect-hot-links-inner").enableSelection();               
    });
    $('.button-editgroup button.button-cancel').click(function () { //Click "cancel" button 
            $(".sect-hot-links-inner").sortable('cancel');
            $(".sect-hot-links-inner").sortable('disabled');
            $(".sect-hot-links-inner").enableSelection();   
    });

I've already tried to change .sortable() to .sortable('enable') at #tune-hot-links event. And it's not working.

Upvotes: 4

Views: 8147

Answers (1)

Dazvolt
Dazvolt

Reputation: 697

Well, I have no idea why, but seems that changing code like this:

$('#tune-hot-links').on( "click", function() {      
            $(".sect-hot-links-inner").sortable("enable");          
    });
    $('.button-editgroup button.button-save').on( "click", function() {         
            $(".sect-hot-links-inner").sortable("disable");
    });

    $('.button-editgroup button.button-cancel').on( "click", function() {   
            $(".sect-hot-links-inner").sortable('cancel');
            $(".sect-hot-links-inner").sortable("disable");
            $(".sect-hot-links-inner").enableSelection();   
    }); 

Resolved that issue.

Upvotes: 4

Related Questions