2009-07-07 32 views
3

我在SharePoint中有一個自定義列表(特別是MOSS 2007)。一個字段是一個是/否複選框,標題爲「任何缺陷?」。另一個字段是「關閉」並命名已關閉該票證的人員。如何根據其他字段中的值在SharePoint列表字段中設置默認值?

如果沒有缺陷,那麼我希望票證自動關閉。如果有的話,那麼「Closed by」字段應該在稍後填寫。

我想我可以設置這樣的「被關閉」計算的默認值:

=IF([Any defects?],"",[Me]) 

,但抱怨的SharePoint我所引用的字段。我想這是有道理的;當新列表項目首次打開輸入並且任何字段中都沒有值時,默認值將激活。

我知道有可能根據列值計算字段,但在這種情況下,字段不能在以後編輯。

有沒有人有任何建議如何實現我想要做的?

是否可以有一個「OnSubmit」類型的事件,允許我在列表項保存點執行一些代碼?

謝謝。

回答

7

在頁面中包含一個內容編輯器Web部件(newform.aspx/editform.aspx)並使用jQuery(或者簡單的JavaScript)來處理默認值的設置。

編輯:一些示例代碼:

在列表newform.aspx,包括到jquery的一個參考。如果您查看html代碼,您可以看到每個輸入標記都根據字段的GUID獲取一個id,並將字段設置爲display name。

現在,使用jQuery我們可以得到在這些領域使用jQuery選擇這樣的:

按標題:

$("input[title='DISPLAYNAMEOFFIELD']"); 

通過ID(如果您知道該字段的內部GUID,破折號會ahve

// example field id, notice the guid and the underscores in the guid ctl00_m_g_054db6a0_0028_412d_bdc1_f2522ac3922e_ctl00_ctl04_ctl15_ctl00_ctl00_ctl04_ctl00_ctl00_TextField 

$("input[id*='GUID']"); //this will get all input elements of which the id contains the specified GUID, i.e. 1 element 

我們的jQuery ready()功能把這個包,所以所有呼叫都將只進行文檔有完全之時:用下劃線代替加載:

$(document).ready(function(){ 
// enter code here, will be executed immediately after page has been loaded 
}); 

通過結合這2我們現在可以設置您的下拉的onchange事件上EndUserSharePoint.com以下

$(document).ready(function(){ 
$("input[title='DISPLAYNAMEOFFIELD']").change(function() 
{ 
     //do something to other field here 
}); 
}); 
+0

謝謝,我很欣賞使用JavaScript以及如何嵌入它的建議。 是否可以麻煩你稍微進一步對一些示例代碼?我可以將列表中的字段稱爲JavaScript變量嗎? 謝謝! – DavidMWilliams 2009-07-07 07:57:17

+0

見編輯,提供了一些代碼 – Colin 2009-07-07 09:27:38

1

Use jQuery to Set A Text Field’s Value on a SharePoint Form本文將向您展示如何爲現場使用設置的默認值的JavaScript/jQuery的。

他們還有一系列有關'taming calculated columns'的文章,這些文章將向您展示使用jQuery計算字段的許多更強大的選項。

有一點要注意插入JavaScript的時候到SharePoint頁面,修改DOM的是支持。未來的服務包很可能會破壞您添加的功能,而下一個版本的SharePoint很可能會破壞它。然而,保持這種想法,我相信這是一個很好的解決方案。

0

我得通過與示例代碼散步可以幫助

它設置結束時間/日期字段,當你創建一個新的事件開始時間+1.5小時。

其複雜的一點在於以下步驟需要做的時間/日期的工作,但你會看到和如何找到表單上的元素例子也一個辦法讓你的腳本到newform.aspx不使用SPD。

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"> 
</script> 
<script type="text/javascript"> 

    // Set the hours to add - can be over 24 
    var hoursToAdd = 1; 
    // Mins must be 0 or div by 5, e.g. 0, 5, 10, 15 ... 
    var minutesToAdd = 30; 

    // JavaScript assumes dates in US format (MM/DD/YYYY) 
    // Set to true to use dates in format DD/MM/YYYY 
    var bUseDDMMYYYYformat = false; 

    $(function() { 

    // Find the start and end time/minutes dropdowns by first finding the 
    // labels then using the for attribute to find the id's 
    // NOTE - You will have to change this if your form uses non-standard 
    // labels and/or non-english language packs 
    var cboStartHours = $("#" + $("label:contains('Start Time Hours')").attr("for")); 
    var cboEndHours = $("#" + $("label:contains('End Time Hours')").attr("for")); 
    var cboEndMinutes = $("#" + $("label:contains('End Time Minutes')").attr("for")); 

    // Set Hour 
    var endHour = cboStartHours.attr("selectedIndex") + hoursToAdd; 
    cboEndHours.attr("selectedIndex",endHour % 24); 

    // If we have gone over the end of a day then change date 
    if ((endHour/24)>=1) 
    { 
     var txtEndDate = $("input[title='End Time']"); 
     var dtEndDate = dtParseDate(txtEndDate.val()); 
     if (!isNaN(dtEndDate)) 
     { 
      dtEndDate.setDate(dtEndDate.getDate() + (endHour/24)); 
      txtEndDate.val(formatDate(dtEndDate)); 
     } 
    } 

    // Setting minutes is easy! 
    cboEndMinutes.val(minutesToAdd);  

}); 

// Some utility functions for parsing and formatting - could use a library 
// such as www.datejs.com instead of this 
function dtParseDate(sDate) 
{ 
    if (bUseDDMMYYYYformat) 
    { 
     var A = sDate.split(/[\\\/]/); 
     A = [A[1],A[0],A[2]]; 
     return new Date(A.join('/')); 
    } 
    else 
     return new Date(sDate); 
} 

function formatDate(dtDate) 
{ 
    if (bUseDDMMYYYYformat) 
     return dtDate.getDate() + "/" + dtDate.getMonth()+1 + "/" + dtDate.getFullYear(); 
    else 
     return dtDate.getMonth()+1 + "/" + dtDate.getDate() + "/" + dtDate.getFullYear(); 
} 

</script> 
相關問題