2015-04-30 188 views
0

如何禁用x-editable提交按鈕?我不希望在其他事件中永久禁用它,我需要重新啓用它。以下是我的嘗試。如何禁用x-editable提交按鈕

https://jsfiddle.net/fndnu5m0/1/

$(function() { 

    $('#name').editable({ 
     type: 'text', 
     title: 'Name', 
     url: '/echo/json/', 
     pk: 123, 
     inputclass: 'autocomplete' 
    }). 
    on('shown', function(event, edit) { 
     console.log('on', this, edit) 
     $(document).find('input.autocomplete').val('') 
     .parent().next().find('button.editable-submit').css('opacity', 0.3).off('click'); 
    }); 

}); 
+0

你能解釋userflow是如何假設去,像你想讓用戶點擊一次,然後將其禁用 –

+0

@MuhammadUmer我的最終目標是使用jQueryUI的自動完成與X編輯。我幾乎在https://jsfiddle.net/fndnu5m0/上實現了它。如果你看到這個小提琴,你會看到我的用戶流只是在用戶點擊自動完成項目後才激活提交按鈕。謝謝! – user1032531

+1

更好的實現我以前的嘗試,但仍然無法正常工作。 https://jsfiddle.net/fndnu5m0/3/ – user1032531

回答

1

綁定一個新的點擊事件所涉及的元素。要重新啓用提交按鈕,請移除該事件(未顯示)。不知道這是否是最好的選擇,並且想要評論(如果提供了良好的評論,甚至可以降價)。

https://jsfiddle.net/fndnu5m0/7/

$(function() { 

    $('#name').editable({ 
     type: 'text', 
     title: 'Name', 
     url: '/echo/json/', 
     pk: 123, 
     inputclass: 'autocomplete' 
    }). 
    on('shown', function(event, edit) { 
     console.log('on', this, edit) 
     $(document).find('input.autocomplete').val('') 
     .parent().next().find('button.editable-submit').css('opacity', 0.3) 
     .bind('click',function(){return false;}); 
    }); 

});