在Newform.aspx SharePoint 2013中隐藏列

时间:2014-09-24 15:42:44

标签: javascript sharepoint-2013 csom

如何在使用JSOM安装新列表的过程中删除“title”字段?

我在线使用Sharepoint 2013。

我的代码:

var field1 = newList.get_fields().addFieldAsXml(
    "<Field Type='UserMulti' DisplayName='Name' Description='c' Required='FALSE' ShowField='NameWithPictureAndDetails' Name='Name'  Mult='FALSE' UserSelectionMode='PeopleAndGroups' />", true, SP.AddFieldOptions.addFieldInternalNameHint);

currentContext.load(field1);
currentContext.executeQueryAsync(onListCreationSuccess, onListCreationFail);
}

function onListCreationSuccess() {

var list = hostweb.get_lists().getByTitle("AnstalldDatum");

    var fieldToEdit = list.get_fields().getByTitle("Title");
    fieldToEdit.setShowInDisplayForm(false);
    fieldToEdit.setShowInNewForm(false);
    fieldToEdit.setShowInEditForm(false);
    fieldToEdit.set_hidden(true);
    fieldToEdit.update();

    currentContext.executeQueryAsync(function () {

        console.log("Sucess: Fields installed! ");
        $(".status").append('List Installed');

     });
}

1 个答案:

答案 0 :(得分:3)

以下方法允许控制列表表单中的字段可见性:

以下示例演示了如何使用JSOM在List Forms中设置字段可见性:

function setFieldVisibility(listTitle,fieldName,properties,success,failure)
{
     var ctx = SP.ClientContext.get_current(); 
     var web = ctx.get_web(); 
     var list = web.get_lists().getByTitle(listTitle);
     var field = list.get_fields().getByTitle(fieldName);
     field.setShowInDisplayForm(properties.ShowInDisplayForm);
     field.setShowInNewForm(properties.ShowInNewForm);
     field.setShowInEditForm(properties.ShowInEditForm);
     field.set_hidden(properties.Hidden);
     field.update();
     ctx.executeQueryAsync(success,failure);
}

<强>用法

隐藏新表单页面中的Title字段:

var listTitle = 'Custom List';
var fieldName = 'Title';


var properties = {
      'ShowInDisplayForm': true,
      'ShowInNewForm': false,
      'ShowInEditForm': true,
      'Hidden': false
};
setFieldVisibility(listTitle,fieldName,properties,
   function () {
      console.log("Field visibility settings has been changed");
   },
   function(sender,args){
      console.log(args.get_message());
   }
);