0

i have two lists connected with ui-sortable. My problem is: if an element of the right list (rightModel) has the class 'sorted-list--unsortable', i want to prevent the drop on left list, but continue to drop on the original list. I tried with ui.sender.sortable, but the following appear:

TypeError: ui.sender is null

And i really don't understand how to do it. This is the html page with the two lists:

<div class="sortable-dual-list">

    <div class="row">
        <div class="col-lg-6">
            <h4 class="text-left">{{ $ctrl.leftTitle | translate}}</h4>
            <div class="grid-container grid-container-edit">
                <div class="p-grid-row connector sortable-list" ui-sortable="$ctrl.sortableOptions" ng-model="$ctrl.leftModel" >
                    <div ng-repeat="company in $ctrl.leftModel">
                        <p>{{company.businessName}}</p>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-lg-6">
            <h4 class="text-left">{{ $ctrl.rightTitle | translate}} <label ng-if="$ctrl.required"  class="mandatory">&nbsp;(*)</label>
            </h4>

            <div class="grid-container grid-container-edit">
                <div class="p-grid-row connector sorted-list" ui-sortable="$ctrl.sortableOptions" ng-model="$ctrl.rightModel">

                    <div class="p-row" ng-class="{'sorted-list--unsortable': company.industryValue === 'ACTIVE'}" ng-repeat="company in $ctrl.rightModel">

                        <p>{{company.businessName}} <span ng-if="$first">
                            (default)
                        </span></p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

And this is the sortable options:

    public sortableOptions = {
        connectWith: '.connector',
        disabled: false,
        stop: function(ev, ui) {
            if(ui.item.hasClass("sorted-list--unsortable")){
                ui.sender.sortable('cancel');
            }
        },
    };

1 Answer 1

0

Found the solution:

    public sortableOptions = {
      connectWith: '.connector',
      disabled: false,
      cancel: '.sorted-list--unsortable'
      update: function (event, ui) {
        if (!ui.item.sortable.received &&
            ui.item.sortable.source[0] !== ui.item.sortable.droptarget[0] &&
            ui.item.hasClass('sorted-list--unsortable')) {
            ui.item.sortable.cancel();
        }
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.