Jquery-ui 拖放。下拉列表包含动态创建的文本框,无法编辑

问题描述 投票:0回答:1

动态创建的文本框在 JQuery UI 中不可编辑。使用拖放选项在放置项目时添加了文本框和项目。但文本框不可编辑。 文本框在 Firefox 中不可编辑。 Chrome 工作正常。 任何想法都会有很大的帮助。请分享不同的方法来满足要求。

jsfiddle.net/dsriniudt/xxndahs2/

javascript jquery html jquery-ui
1个回答
0
投票

对于您的问题,我们将允许在删除标签后对其进行编辑。完成后,应将其另存为标签。

工作示例: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 或者单击关闭输入,它将保存当前值。

© www.soinside.com 2019 - 2024. All rights reserved.