Reputation: 2717
I am working on a project which uses the jquery-ui sortable widget.
Under certain circumstance, I need to ask the user a question that relates to the sort, then the update
callback will behave differently depending on their answer.
I have this working using the built in confirm
function, however I need to be able to customize the buttons, which is not possible. Jsfiddle linked below.
If I switch to a custom prompt then I don't think I can make it blocking, which means the sort finishes before the user has answered the question.
Is there a way I can "pause" the sort until the user has answered the question, so I can end up with the equivalent functionality of the below example, but with a customized confirm dialog?
For the purposes of this question, we can assume that the custom confirm dialog could be called as follows (based on the code in the jsfiddle):
beforeStop:function(e,u) {
// Pause the sort
customConfirmDialog("Do you want to do something special?", function(result) {
if (result) {
// They said yes
u.item.addClass("special");
}
// Allow the sort to continue here
});
}
Upvotes: 0
Views: 45
Reputation: 1537
If you read the docs for the cancel method it say:
Cancels a change in the current sortable and reverts it to the state prior to when the current sort was started. Useful in the stop and receive callback functions.
I assume that you could always cancel the event and then move the item yourself once they confirm. You can probably record the previous sibling of the placeholder (or itself if in the stop method, I guess) in order to know where to place it (will be empty if moving to the top of the list).
You may need to use refresh and/or refreshPositions as well in order to make everything work (I'm guessing refreshPositions
).
Upvotes: 0