Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery draggable enable and disable

Ive tried anything to do this, but always get the same error

$(".tooltip").draggable('disable');

Error: cannot call methods on draggable prior to initialization; attempted to call method 'disable'

Prior to initialization? So I cannot remove the option before its actually being dragged around? Ive tried with droppable as well, cant seem to get them disabled enabled without getting this error.

edit: I found out that I have an element with the class that is without draggable (which makes sense when you look at the error). Now I just have to find a way so it disables all the draggables without throwing the error :)

like image 977
Gleiemeister 2000 Avatar asked Nov 29 '12 16:11

Gleiemeister 2000


People also ask

Why draggable is not working?

Check whether your draggable object is already loaded in the viewport. If it is not, it won't work properly. JUST AFTER the draggable object to be absolutely sure that everything is loaded at the correct time. When you'll be sure everything is ok, then you'll be able to refactor.

How do I get rid of draggable?

Syntax: $( ". selector" ). draggable({ disabled: true/false });

What is jQuery draggable?

jQuery UI draggable() method is used to make any DOM element draggable. Once the element is made draggable, you can move it by clicking on it with the mouse and drag it anywhere within the viewport.

How do you make something draggable in jQuery?

Using jQuery UI, we can make the DOM(Document Object Model) elements to drag anywhere within the view port. This can be done by clicking on the draggable object by mouse and dragging it anywhere within the view port. If the value of this option is set to false, it will prevent the DOM elements to be dragged .


2 Answers

Try this:

$(".tooltip").draggable({ disabled: true });

This initializes the draggable in the disabled state. You can then use

$(".tooltip").draggable("enable");

later when you want to allow dragging.

like image 79
Barmar Avatar answered Sep 20 '22 20:09

Barmar


I was able to recreate your scenario in this jsfiddle:

http://jsfiddle.net/dboots/NDZKY/

This is using

$('.draggable').draggable('disable');

and

$('.draggable').draggable('enable');

Is there something different that you're not able to do the same? Looks like you have the same syntax.

like image 40
Don Boots Avatar answered Sep 17 '22 20:09

Don Boots