2

I'm creating a SharePoint list with JavaScript, now I want to hide the title field in the same process.

How can I achieve this?, I was trying to add a jslink, and in that document, hide the title field with JSRendering.

But I can't add a jslink programmatically, I tried this but it doesn't work:

var list = hostweb.get_lists().getByTitle("");
var view = list.get_views().getByTitle("");

var viewCreationInformation = new SP.ViewCreationInformation();
viewCreationInformation.set_title("");

var viewType = new SP.ViewType();
viewCreationInformation.set_viewTypeKind(viewType.html)
view = list.get_views().add(viewCreationInformation);
view.set_jsLink("~site/SiteAssets/test.js");

view.update();
currentContext.load(view);
currentContext.executeQueryAsync(onViewCreationSuccess, onViewCreationFailed);
  • To hide a field by javascript try this: $("input[title='Title']").closest("tr").hide(); – Nk SP Sep 25 '14 at 9:20
  • You can do by making Title column as hidden in List Item content type and then remove checkbox from Title column in view. In that way, it will neither appear in its newform/editform nor will display in its view. – ateet Sep 25 '14 at 9:22
  • I must do it programmatically, and in the same process as when im creating the list. Thats why NK SP will not work. – Anders Sep 25 '14 at 9:45
5

The following example demonstrates how to control field visibility in List Forms using JSOM

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);
}

Usage

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


var properties = {
      'ShowInDisplayForm': false,
      'ShowInNewForm': false,
      'ShowInEditForm': false,
      'Hidden': true
};
setFieldVisibility(listTitle,fieldName,properties,
   function () {
      console.log("Field visibility settings has been changed");
   },
   function(sender,args){
      console.log(args.get_message());
   }
);
  • Thank you, well the field does not hide in the view. But it hides itself in dispform, newform. But not in the view – Anders Sep 25 '14 at 11:37
  • You can't just modify the view settings and un-select the title field...? There is no requirement that the title field be displayed in a list view... – John-M Sep 25 '14 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.