4

is it possible to disable onclick="" while sorting?

I Have a working example here http://www.jsfiddle.net/V9Euk/59/

Peter

Justin
  • 84,773
  • 49
  • 224
  • 367
Peter
  • 43
  • 1
  • 3

2 Answers2

3

you can use start and stop options:

$( ".selector" ).sortable({
   start: function(event, ui) { ... },
   stop: function(event, ui) { ... }
});

Just create a flag and set to true when sorting started and to false when the sorting is over and in your onclick function check the flag first:

var isBeingSorted = false

$( ".selector" ).sortable({
   start: function(event, ui) { isBeingSorted = true; },
   stop: function(event, ui) { isBeingSorted = false; }
});

function printAlert(message){
   if(!isBeingSorted)
       alert(message);
}

And of course your onclicks should look like onclick="printAlert('sdfsdf')"

For more options look here

Maksim Vi.
  • 9,107
  • 12
  • 59
  • 85
1

If you don't want to do it with a flag variable as per @nigative , you can do the following with the start and stop methods:

$("#lop").sortable({
  revert: '100',
    placeholder: 'auo',
    start: function(event, ui) {
       ui.item[0].oldclick = ui.item[0].onclick;
       ui.item[0].onclick = null;     
    },
    stop: function(event, ui) {
       ui.item[0].onclick = ui.item[0].oldclick;
    }
});
jdd
  • 4,301
  • 1
  • 27
  • 28
  • This wouldn't work for me because as I dropped the item the onclick was still being detected. I was able to work around this by using setTimeout when restoring the onclick function: `setTimeout(function(){ ui.item[0].onclick = ui.item[0].oldclick }, 500);` – vertigoelectric Jan 30 '13 at 07:45