Friday, June 5, 2009

[jQuery] Re: ui sortable - cancel action if list is too long

Maybe you could supply a function for the accept option and have it return false if the max is reached, otherwise true:

http://docs.jquery.com/UI/Droppable#option-accept

Also note, there's a dedicated mailing list for jQuery UI plugins:

http://groups.google.com/group/jquery-ui

- Richard

On Fri, Jun 5, 2009 at 3:48 AM, Robert Bobrowski <robert.bobrowski@gmail.com> wrote:

I have few lists with ui sortable/droppable and I want to have let say
max 4 elements in one. So:

$("ul[id^='sortable']").sortable({
       connectWith: '.user-list',
       dropOnEmpty: true
})

$(".accept-drop").droppable({
       drop: function(event, ui) {
               //some code

               if($('#sortable'+new_id+" li").size()>4) {
               //DO SOMETHING TO STOP SORTABLE
       }
});

What code should be there? I've tried to change class to .disabled but
it blocks moving.
$('#sortable'+new_id).sortable("cancel"); causes error. Script allows
to move single elements and whole lists.
I want to be able move elements from all lists but disable drop if
it's too long.

--
Regards,
Robert

No comments: