2013-02-08 52 views
1

我已經找到了一些答案解釋如何從這裏一個文本框http://www.kendoui.com/forums/ui/general-discussions/method-for-removing-controls.aspx刪除劍道UI kendoDatePicker小部件,這裏http://www.kendoui.com//forums/ui/date-time-pickers/datepicker-becomes-static.aspx取下文本NumericTextBox構件

不幸的是,上面的例子似乎並沒有幫助,當我嘗試刪除一個NumericTextBox的屬性。我結束了與源代碼下面。

var numericTextBox = $(selector).data("kendoNumericTextBox"); 
    var element = numericTextBox.wrapper[0] ? numericTextBox.wrapper 
      : numericTextBox.element; 

    // unwrap element 
    var input = numericTextBox.element.show(); 
    input.removeClass("k-input").css("width", "12.4em"); 
    input.removeClass("numerictextbox"); 
    input.insertBefore(numericTextBox.wrapper); 

    numericTextBox.wrapper.remove(); 

    input.removeAttr("data-role"); 
    input.removeAttr("role"); 

我終於結束了一個文本框,看起來像一個簡單的文本框,但我仍然不允許添加任何東西不僅僅是數字別人。 此外,我嘗試添加行input.removeData(「kendoNumericTextBox」);這接近我在上面發佈的鏈接上建議的內容,但我無法確定此行的功能。

+0

東西非常基本的,有什麼你試圖完成(最終目標)?我想了解你最終想要獲得什麼,因爲也許有一些更簡單的方法來完成它,開始剝離'numericTextBox'。 – OnaBai 2013-02-09 06:14:52

+0

我有一個kendoNumericTextBox,我想要轉換爲簡單的輸入文本框。更詳細地說。我有一個組合框,它有int和string類型。當從列表中選擇一個int值時,輸入字段將轉換爲kendoNumericTextBox。這部分工作。當選擇字符串值時,不起作用的是將kendoNumericTextBox恢復爲簡單的輸入文本字段。 – Stephan 2013-02-11 08:02:08

回答

2

而不是玩小部件裝飾從文本轉換爲數字,反之,它更容易擁有並且總是隱藏其中之一。你只需要添加一個類/刪除一個類,並獲得正確的可見。

比方說,我有以下CSS定義:

.ob-hide { 
    display: none; 
} 

下面的HTML:

<div id="combobox"></div> 
<div id="number"></div> 
<div id="text"></div> 

然後我的JavaScript將是:

$("#combobox").kendoDropDownList({ 
    dataSource: { 
     data: [ "string", "number" ] 
    }, 
    value  : "string", 
    change : function (e) { 
     console.log("change"); 
     if (this.value() === "string") { 
      console.log("string"); 
      $("#number").closest(".k-numerictextbox").addClass("ob-hide"); 
      $("#text").closest(".k-autocomplete").removeClass("ob-hide"); 
     } else { 
      console.log("number"); 
      $("#number").closest(".k-numerictextbox").removeClass("ob-hide"); 
      $("#text").closest(".k-autocomplete").addClass("ob-hide"); 
     } 
    } 
}); 
$("#number").addClass("ob-hide").kendoNumericTextBox({}); 
$("#text").kendoAutoComplete({}); 
+0

好主意!這使我的代碼減少了很多。像魅力一樣工作。再次非常感謝你! – Stephan 2013-02-11 13:02:09

+0

好主意!這使我的代碼減少了很多。像魅力一樣工作。 – Stephan 2013-02-11 13:02:52