2017-03-15 22 views
0

动态创建的文本框在JQuery UI中不可编辑。使用的拖放选项删除项目时添加了文本框和项目。但是文本框不可编辑。 文本框在Firefox中不可编辑。 Chrome工作正常。 任何想法都会很有帮助。请分享不同的方法,以满足要求。Jquery-ui拖放。删除的列表包含无法编辑的动态创建的文本框

jsfiddle.net/dsriniudt/xxndahs2/

+0

https://jsfiddle.net/dsriniudt/xxndahs2/ –

+0

当我尝试小提琴的文本框是可编辑的。请解释 – user7491506

+0

@srinivasanD我怀疑你的意思是允许用户更改项目标签。就像现在一样,当您放置该项目时,文本框将被追加并且可编辑。看起来你想在用户点击标签时允许这一点。它是否正确? – Twisty

回答

0

我认为这是你在找什么,并在未来它是最好的,包括一个适当的例子。请阅读:

https://stackoverflow.com/help/mcve

对于您的问题,我们要允许它已被删除后的标签进行编辑。一旦完成,它应该被保存为标签。

工作实例:https://jsfiddle.net/Twisty/xxndahs2/6/

的JavaScript

$(function() { 
    $("#sortable1, #sortable2").sortable({ 
    connectWith: ".connectedSortable, .connectedSortable1" 
    }).disableSelection(); 

    $("#sortable2").droppable({ 
    cancel: "#addCustomTitle", 
    disabled: false, 
    drop: function(e, ui) { 
     // Use class 'cutomLabel' to identify labels that can be edited 
     ui.draggable.addClass("customLabel"); 
    } 
    }); 

    $("#sortable2").on("click", ".customLabel", function(e) { 
    console.log("Click capture, opening Text Box."); 
    // Capture current text 
    var currentLabel = $(this).text(); 
    // Replace current HTML with Input field 
    $(this).html($("<input>", { 
     class: "entryField", 
     type: "text", 
     value: currentLabel 
    })); 
    // Set focus inside input field 
    $(this).find("input").focus(); 
    return false; 
    }); 

    $("#sortable2").on("blur keypress click", ".entryField", function(e) { 
    console.log(e); 
    switch (true) { 
     case e.keyCode == $.ui.keyCode.ENTER: 
     case e.keyCode == $.ui.keyCode.TAB: 
     case e.originalEvent == "blur": 
     case e.type == "focusout": 
     console.log("Leaving field or Enter was struck, saving value."); 
     // Capture value of input field 
     var currentValue = $(this).val(); 
     // Replace HTML with text 
     $(this).parent().html(currentValue); 
     break; 
    } 
    }); 
}); 

所以,你不妨换个如何 “拯救” 发生。你可以添加按钮,但我怀疑你正在寻找点击或导航类型模型。所以如果用户点击ENTERTAB或者他们点击输入,它会保存当前值。

+0

添加了一些UI触摸:https://jsfiddle.net/Twisty/xxndahs2/8/ – Twisty

+0

感谢您的意见..我只是在寻找可编辑的文本框。感谢您的大力帮助 –

+0

解决了小提琴http://jsfiddle.net/dsriniudt/xxndahs2/12/ –