Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6118937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:29:40+00:00 2026-05-23T15:29:40+00:00

I have a draggable that is connected via connectToSortable to multiple sortables. I want

  • 0

I have a draggable that is connected via connectToSortable to multiple sortables. I want to limit the number of items you can put in each sortable. I can do this when you drag from another sortable, but not when you drag from the draggable to the sortable. A simple example (as JSBin):

$( ".sortable" ).sortable({
  connectWith: ".sortable"
});

$( ".sortable" ).bind( "sortreceive", function(event, ui) {
  // This will not work because the sender is a draggable, which has no "cancel" method
  if ( 4 < $( this ).sortable( 'toArray' ).length ) {
    $(ui.sender).sortable('cancel');
  }
});

$( "#draggable li" ).draggable({
  connectToSortable: ".sortable",
  helper: 'clone'
});

I first tried $(ui.sender).sortable('cancel'); in the sortreceive event, but because the sender is a draggable, not another sortable, it does not have a cancel method and this does not work (so these and these questions don’t seem to solve my problem). I have tried following the logic that glues the draggable and the sortable together, but I see no place to jump in and cancel the “faked” stop.

It would be great if there was some kind of visual feedback, like the mouse cursor changing to no-drop, and/or a background color change on the sortable.

Context: This is an attempt to answer Limit number of Widgets in Sidebars on the WordPress Stack Exchange. The WordPress widget administration page has a container with all available widgets set up as a draggable, connected to different sortable containers for each sidebar. I don’t want to modify the core code, just extend it with as little code as needed to prevent dropping another widget on a “full” sidebar.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:29:41+00:00Added an answer on May 23, 2026 at 3:29 pm

    Just add the if clause to check the number of elements in the sortable and unbind the draggable event when u have reached that number.

    EDIT: (Includes multiple list support now)

    $('.draggable').draggable({revert:true,helper:'clone',connectToSortable: '.sortable'});
    
    $('.sortable').sortable({
        connectWith:'.sortable',
        receive: function(ui) {
            if($(this).children().length >=6) {
                $(this).children().addClass('filled');
                $(this).addClass('dontDrop');
                $('.sortable').sortable('option', 'connectWith',$('.sortable').not('.dontDrop'));
                $('.draggable').draggable('option', 'connectToSortable',$('.sortable').not('.dontDrop'));
            }else {
                $(this).children().removeClass('filled');
            }
            add_delete();
        }
    });
    function add_delete() {
        $('.delete').remove();
        $('.sortable>li').append('<span class="delete">--</span>');
        $('.delete').unbind('click').click(function(){
            if($(this).parent().siblings().length <=5) {//for atmost 6 children in sortable
                $(this).parent().parent().children().removeClass('filled');
                $(this).parent().parent().removeClass('dontDrop');
                console.log($('.sortable').not('.dontDrop'));
                $('.sortable').sortable('option', 'connectWith',$('.sortable').not('.dontDrop'));
                $('.draggable').draggable('option', 'connectToSortable',$('.sortable').not('.dontDrop'));
            }
            $(this).parent().hide('slow').remove();
        });
    }
    add_delete();
    

    Check fiddle here JSFiddle

    So what I have used here is: One can pass not just selectors but elements themselves to the connectWith/connectToSortable options. Whenever an ‘ul’ has 6 elements I give it the class ‘dontDrop’ and it is hence excluded from the connections.
    Hope this clears it out for you.

    Let that bounty come this way 😀

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have: String uri = @drawable/myresource.png; How can I load that in ImageView? this.setImageDrawable?
Basically I have a draggable list which is connected with a sortable list. Works
I have a draggable object (div), and some droppable ones (table TD's). I want
I am trying to create to movable instances, that are draggable, and which have
I have a draggable container that was working with jquery 1.3.2. I recently upgraded
I have an iPad app that has draggable UIViews contained in a larger parent
I have a draggable view that a user will touch, but some rectangles of
I have a draggable view that I have set up with the following code:
I have been using raphael.draggable with a project that I am currently building. I
Hello dearest community. I have trouble in the last two days, that I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.