jQuery sortable cancel event if not valid

前端 未结 2 1271
逝去的感伤
逝去的感伤 2021-01-21 05:11

I have a list which is sortable. Before I start sorting, I want to check if all the elements of that list are valid. If not, cancel the event and leave the list intact.

2条回答
  •  爱一瞬间的悲伤
    2021-01-21 05:50

    You can use the cancel method

    $("#list").sortable({
        connectWith: ".connectedSortable",
        items: '.sortable-item',
        handle: '.handle',
        placeholder: "ui-state-highlight",
        stop: function (event, ui) {
            console.log('stop')
            if (!valid()) {
                $( this ).sortable( "cancel" );
            }
        }
    });
    

    Demo: Fiddle

提交回复
热议问题