views:

264

answers:

4

I'm using jquery-ui's draggable for drag-and-drop, and jeditable for inline editing.

When I drag and drop an element that's also editable, right after it's dropped jeditable kicks in and pops into 'edit mode'.

How can I disable this behavior?

Edit - the problem happens because of netsting - see this example. I also added draggable to the mix to make the example more realistic (the actual real problem is in this site that I'm working on)

Note - even though this question has an accepted answer because of the bounty rules, the problem is still not resolved for me.

A: 

oftomh, you should try and get a hold of the Event object within the drop handler, and then try to call event.preventDefault(), event.stopImmediatePropagation() or event.stopPropagation()

luckily for you you're on jQuery. Doing so cross-browserly with vanilla JS is annoying.

Ken Egozi
It appears the problem doesn't happen when the dragabble and editable are the same object (see @aSeptik's answer). Here is a live example of my problem: http://jsbin.com/izaje3
ripper234
A: 

Ripper,

One possible workaround is to use the double click event for your jEditable component.

To do this, just initialize the jEditable object with the following option:

event: 'dblclick'
jverdi
This defeats the purpose, I absolutely need the trigger to be a single click.
ripper234
+5  A: 

UPDATED 2: use children()

DEMO 2: http://jsbin.com/izaje3/2

in responce to your comment

$(function() {
    $('.editable').editable();
    $('.draggable').draggable({
        drag: function(event, ui) {
            $(this).children('div').removeClass('editable')
        },
        stop: function(event, ui) {
           $(this).children('div').addClass('editable')
        }
    });
});​

DEMO: http://jsbin.com/ihojo/2

$(function() {
    $(".draggable").draggable({
        drag: function(event, ui) {
            $(this).unbind('editable')
        }
    });
    $(".editable").editable();
});

OR you can do like this:

$(function() {
    $('.editable').editable();
    $('.draggable').draggable({
        drag: function(event, ui) {
            $(this).removeClass('editable')
        },
        stop: function(event, ui) {
            $(this).addClass('editable')
        }
    });
});

Assuming you have something like this:

<div class="draggable editable"></div>  

NOTE: just for sake, you can also take advantage by using the handle method!

http://jqueryui.com/demos/draggable/#handle

aSeptik
Looks like your demo is working, cool !I haven't yet integrated your solution to my own code base, I'll accept this as soon as I have.
ripper234
sure i have tested it in all win browsers! ;) in anycase try it local cause jsbin sometimes suck with some browser!
aSeptik
There seems to be some other problem with my code - see this example that works, although I am no longer unbinding the method: http://jsbin.com/ihojo/23
ripper234
The problem I'm having is because of nesting - it's not the same elements that's editable and draggable: http://jsbin.com/izaje3
ripper234
see the updates!
aSeptik
Accepted, thanks.
ripper234
Sorry to be a bother, but when I tried to apply to my code I'm still not getting it to work :(I don't understand why your example works in the first place - by the time you call $(this).removeClass('editable'), jQuery already added the hooks, so it's now "too late".Here is my non-working example: http://jsbin.com/izaje3/5I updated my example a
ripper234
A: 

You could try setting contenteditable="false" on these items. Just try adding this attribute in the relevant html tag and see what happend.

Rolf