rniemeyer / knockout-sortable

A Knockout.js binding to connect observableArrays with jQuery UI sortable functionality
MIT License
548 stars 128 forks source link

Confirmation popup before aftermove is executed #196

Open mrshawn191 opened 6 years ago

mrshawn191 commented 6 years ago

Hi I have this piece of code

            <div class="query-result" data-bind="onWindowResize: 218">
                <ul class="nav nav-pills nav-stacked" data-bind="sortable: { template: 'query-result-item-template', aftermove: reorder, data: $page.child('read')().children }">
                </ul>
            </div>

Its a list, and everytime you move each item a function reorder is executed.

My question is it possible to add a confirmation popup before the reorder function is executed? I want to warn the user about the action he is going to perform.

derrickb commented 6 years ago

You can use the beforeMove handler and set arg.cancelDrop to true if the user wishes to cancel the move.

ko.bindingHandlers.sortable.afterMove = function (arg, event, ui) {
  //show popup, get user response, set arg.cancelDrop accordingly
}