简体   繁体   中英

SharePoint List, display calculated field in edit form

I have several SharePoint lists that have a calculated field, which is calculated from the ID field, eg if the ID is 13, the calculated field is "XX00013", where "XX" indicates the purpose of this particular list.

By default, in the Display From, this "XX00013" is shown.

How can I make it shown as read-only in the Edit Form too? So that the user who is editing the entry always can see which entry s/he is editing?

I don't think I can edit the EditForm, as it's restricted by the webmaster. I do have access to Content Editor Web Part to edit some javascript code. Any suggestions?

I tried to put following code in the in the Content Editor Web Part, which is added to the Edit page. It works so far that the "XX00013" is shown as ready-only in the Edit form. This solution is just a walk-around.

Still the question of in general how to show calculated field remains.

<script type="text/javascript"> 
function DisplayID(){ 
 var regex = new RegExp("[\\?&]"+"ID"+"=([^&#]*)"); 
 var qs = regex.exec(window.location.href); 
 var sID = qs[1];
 var stID="XX";
 var nLength=5-sID.length;
 var i=0;
 do{
  stID=stID.concat("0");
  i++;
 }while (i<nLength) 
 stID=stID.concat(sID);
 var TD1 = document.createElement("TD"); 
 TD1.className = "ms-formlabel"; 
 TD1.innerHTML = "<h3 class='ms-standardheader'>XX_ID</h3>";
 var TD2 = document.createElement("TD"); 
 TD2.className = "ms-formbody"; 
 TD2.innerHTML = stID; 
 var IdRow = document.createElement("TR"); 
 IdRow.appendChild(TD1); 
 IdRow.appendChild(TD2); 
 var ItemBody = GetSelectedElement(document.getElementById("idAttachmentsRow"),"TABLE").getElementsByTagName("TBODY")[0];
 ItemBody.insertBefore(IdRow,ItemBody.firstChild);
}   
_spBodyOnLoadFunctionNames.push("DisplayID");
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM