jeditable 意外触发嵌套项目上的 Draggable

发布于 2024-08-31 01:09:32 字数 523 浏览 3 评论 0原文

我使用 jquery-ui 的 Draggable 进行拖放,使用 jeditable 进行内联编辑。

当我拖放一个也可编辑的元素时,在它被放置后,jeditable 立即启动并弹出到“编辑模式”。

我怎样才能禁用这种行为?

编辑 - 由于netsting而出现问题 - 请参阅此示例。我还添加了 Draggable 到混合中,使示例更加真实(实际的真正问题是在 这个网站 中,我是正在处理)

注意 - 尽管由于赏金规则这个问题有一个可接受的答案,但对我来说问题仍然没有解决。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

霞映澄塘 2024-09-07 01:09:32

更新2:使用children()

演示2: http: //jsbin.com/izaje3/2

响应您的评论

$(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();
});

或者你可以这样做:

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

假设你有这样的东西:

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

注意:只是为了方便,你也可以通过使用处理方法!

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

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

人间不值得 2024-09-07 01:09:32

我发现这篇文章是因为我今天遇到了这个确切的问题(将 jEditable 嵌套在 jQuery UI Draggable 中);虽然我不认为我的解决方案特别优雅,但我觉得我应该分享它,以防其他人遇到同样的问题。

我发现将 jEditable 设置为使用仅在 mouseup 时触发的自定义事件更容易未拖动可拖动对象(模拟单击)。

如果您喜欢的话,作为 editable 第一个参数的匿名函数应该替换为您要发布到的 url。

http://jsbin.com/izaje3/13

var notdragged = true;
$('.editable').editable(function(value, settings) {
        return value;
    }, {event : 'custom_event'
});
$('.draggable').draggable({
    start: function(event, ui) {
        notdragged = false;
    }
});

$('.editable').bind('mousedown', function() {
    notdragged = true;
}).bind('mouseup', function() {
    if (notdragged) {
        $(this).trigger("custom_event");
    }
});

I found this post because I came across this exact problem (nested jEditable inside a jQuery UI Draggable) today; while I don't think my solution is particularly elegant I felt like I ought to share it in case someone else has the same problem.

Instead of trying to unbind and reinitialize the jEditable on the drag events (which seems to fire the click event AFTER the reinitialization on stop()), I found it easier to set the jEditable to use a custom event which is only triggered on mouseup if the draggable wasn't dragged (simulating a click).

The anonymous function as the first argument of editable should be replaced with the url you're POSTing to if that's your thing.

http://jsbin.com/izaje3/13

var notdragged = true;
$('.editable').editable(function(value, settings) {
        return value;
    }, {event : 'custom_event'
});
$('.draggable').draggable({
    start: function(event, ui) {
        notdragged = false;
    }
});

$('.editable').bind('mousedown', function() {
    notdragged = true;
}).bind('mouseup', function() {
    if (notdragged) {
        $(this).trigger("custom_event");
    }
});
暗恋未遂 2024-09-07 01:09:32

oftomh,您应该尝试在放置处理程序中获取 Event 对象,然后尝试调用 event.preventDefault()event.stopImmediatePropagation( )event.stopPropagation()

幸运的是,您使用的是 jQuery。使用 vanilla JS 跨浏览器这样做很烦人。

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.

伪心 2024-09-07 01:09:32

Ripper,

一种可能的解决方法是对 jEditable 组件使用双击事件。

为此,只需使用以下选项初始化 jEditable 对象:

event: 'dblclick'

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'
骷髅 2024-09-07 01:09:32

您可以尝试在这些项目上设置 contenteditable="false"。
只需尝试在相关 html 标签中添加此属性,看看会发生什么。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文