Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

156
Visualizações
Cancel dragging of a sortable item

An absolutely common sortable case:

<script>
$(function() {
  $("#sortable").sortable();
});
</script>

<ul id="sortable">
  <li>Item 1</li>
  <li>Item 2</li>
  <li>Item 3</li>
</ul>

Problem. Need to cancel dragging of an item on some condition and there is a good advice of Andrew Whitaker, but that approach is working only for jquery-ui-draggable and fails for sortables:

$("#sortable").sortable({
  start: function() {
    return false; // will still cause `this.helper is null`
  }
});

Will be greateful for suggestions.

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Sortable has a "cancel" capability invoked using sortable('cancel').

From the docs: "Cancels a change in the current sortable and reverts it to the state prior to when the current sort was started." See http://api.jqueryui.com/sortable/#method-cancel.

Example usage:

$("#sortable").sortable({
  stop: function(e, ui) {
    if ("I need to cancel this") {
      $(ui.sender).sortable('cancel');
    }
  }
});
over 4 years ago · Santiago Trujillo Relatório

0

Returning false as fudgey suggests works great for making things dynamically unsortable, but there's also a cancel option in the sortable config which lets you set up static unsortables as well:

$("#sortable").sortable({
    // this prevents all buttons, form fields, and elemens
    // with the "unsortable" class from being dragged
    cancel: ":input, button, .unsortable"
});
over 4 years ago · Santiago Trujillo Relatório

0

The sort function callback does the same for sort as drag for draggable (demo):

$("#sortable").sortable({
    sort: function() {
        if ($(this).hasClass("cancel")) {
            $(this).sortable("cancel");
        }
    }
});
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda