2009-05-26 21 views
1

在我當前的asp.net-mvc項目中,我的一個頁面允許用戶在發出發佈請求以更新多個值之後,在下拉框中選擇一個值。 爲了確保回發延遲不會混淆用戶選擇另一個值(從而創建另一個帖子,創建另一個延遲等),我將select的disabled屬性設置爲true。
但是,禁用的輸入不會提交給郵政通話。禁用選擇框,但不刪除帖子中的值

如何讓用戶在視覺上清楚工作正在進行並使其無法在不從帖子中刪除輸入的情況下選擇新值?

回答

1

是的,這也讓我很煩惱。

基本上你需要做的就是隱藏舊的按鈕,並將其替換爲禁用的按鈕,使其看起來與用戶相同。這樣它仍然提交,但不能雙重提交。

其實我找到了什麼似乎是在Problem with disabling submit buttons on form submit這個副本。

0

我在Cletus的帖子中發現的答案都不是我一直在尋找的。
這是我想出來的。它不是100%可重用的,但它可以滿足我的需求並隨時可以改進/編輯。

$('#productMixSelectorForm').change(function() { $(this).ChangeSelection() }); 

jQuery.fn.ChangeSelection = function() { 
    var html = $('<div class="hidden">'); 
    $(this).find('select, input').each(function() { 
     if ($(this).hasClass('hidden') == false) { 
      //Clone the original one into the hidden div 
      html.append($(this).clone()); 
      //Disable the original (visible) one and make it's name unique again 
      $(this).attr("disabled", true); 
      var name = $(this).attr("name"); 
      $(this).attr("name", name + "disabledDummy"); 
     } 
    });  
    //Add the collection of clones to the form so they get submitted 
    $(this).append(html); 
    $(this).submit(); 
} 
1

從你的答案,我收集你已經使用jQuery。在那種情況下,爲什麼你不能獲得選擇框的值,禁用它,然後自己發佈值?

獎勵:BlockUI是一個不錯的jQuery插件,很好的阻止了用戶界面。