Hide some fields for SharePoint list item when creating, updating, viewing

Some times we don't want some fileds dispaly to end user when creating, updating, viewing SharePoint custom list item.

And this field we don't want to show is a cacalute column from other column, e.g. you want to get alias from person and group filed.

But in the default sharepoint cacalute column expression, you can't use the person and group filed.

Fortunately, when you input the person and group filed, there will be a hide filed to store the alias for the person or group.

So we can use the Javacript in the PreSaveAction function of the list form to get the alias and populate it into the hided alias filed, then the sharepoint list form will save it when you clicking saving.

1.  include the Jquery library before writing the follow code

 <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"></script>

for how use Jquery in SharePoint 2010, please check http://blogs.msdn.com/b/yojoshi/archive/2010/06/17/using-jquery-with-sharepoint-2010.aspx

 

2. Hide the table row for the alias field

var aliasInput;
 $(document).ready(function () {    
               
         
       aliasInput = $("input[title='Alias']")[0]; 
       var parent_Alias = aliasInput.parentNode;
       var parent_TR_Alias =  getParentNode_TR(parent_Alias );
       
       parent_Alias.removeChild(aliasInput);
       if(parent_TR_Alias)
       {
           parent_TR_Alias.style.display = "none";
       }
       
       // aliasInput.style.display = "none";
       //  aliasInput.disabled = true;
    });

function getParentNode_TR(parent )
{
     while (parent && parent.tagName != 'TR') {
                    parent = parent.parentNode;
                }
     return parent;
}


3.  Get the alias value from person or group field and populate it to aliasInput.value

function PreSaveAction() {
 // Get the alias and save it to the alias column
    var aliasSpan = $(".ms-entity-resolved").filter(function () {
        return $(this)[0].tagName == "SPAN"
    })[0];  

   var aliasValue = aliasSpan.attributes["title"].nodeValue;
   aliasInput.value = aliasValue;
   aliasInput.disabled = false;
........

}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值