8

I have a list, and all I am trying to do is hide an column for when a user creates a new item, but allow the column to be shown in the edit item page. Currently if I hide a column it is hidden in both fields.

9

You can define this when you add a column in CAML via the ShowInNewForm and ShowInEditForm properties. You can find all the valid properties in the article Field Element (List)

Alternatively, you can set these values using the object model (likely Powershell, since this is a one off run). The properties of the SPField object are the same (ShowInNewForm / ShowInEditForm).

  • Hi, so I do not have access to the server (I'm an intern with only front end access to our sharepoint with developer access), so how would I go about editing the CAML? Sorry, I am extremely new to sharepoint – TrevorTheIntern Jun 20 '14 at 15:48
  • You can't. That's only for new columns. If it's already deployed you'll need to set the property of the SPField object and update the column. There's a proposed answer below using JavaScript as well, though I've never tried that way so YMMV. – RJ Cuthbertson Jun 20 '14 at 15:53
3

The answer from @RJ Cuthbertson is very interesting! So I digged it and I wrote a blog post about that.

I reproduce here what I wrote in my blog:

With the Sharepoint WebServices it’s possible to hide a field into the NewForm, the Editform and/or the DispForm. You’ll need to use JavaScript with jQuery and SPServices. It’s the UpdateList service that will do the trick.

Once you have loaded the both librairies you can use the below code:

var fieldsToUpdate = '<Fields>';
fieldsToUpdate += '<Method ID="1"><Field Type="Text" Name="My_x0020_Field" DisplayName="My Field" ShowInDisplayForm="False" ShowInEditForm="False" ShowInNewForm="False"></Field></Method>';
fieldsToUpdate += '</Fields>';

$().SPServices({
  operation: "UpdateList",
  listName: "Name of the list",
  listProperties:"",
  updateFields: fieldsToUpdate,
  newFields: "",
  deleteFields: "",
  listVersion: "",
  completefunc: function (xData, Status){}
});

As explained into this Stackoverflow’s question you must provide a minimum of three mandatory properties, and in this order:

  1. Type
  2. Name
  3. DisplayName

The Type must reflect the type of your field. This information is available into the MSDN documentation. The most common values should be Boolean | Calculated | Choice | Currency | DateTime | Integer | Lookup | LookupMulti | MultiChoice | Number | Text | User | UserMulti.

The Name is the internal name (usually the spaces are replaced with « x0020 »).

And for each form (ShowInDisplayForm | ShowInEditForm | ShowInNewForm) you can set them to True or False. More properties are available into the MSDN documentation.

  • This is what i needed for an existing list. worked like a charm. – Abdul Hameed Feb 21 '17 at 11:04
2

You can also apply jquery to hide the column.

i.e. $("input[title='Title']").closest('tr').hide();

you have to add content editor web part in newform.aspx of list to apply jquery.

  • Hi, so I am trying to do this, but when I add that snippet to the content editor web part, it doesn't do anything (I changed the 'Title' to the name of one of the fields I want to find). I was able to get some javascript to run from that field, (made an alert box pop up) so it's just an issue of getting this to work. I made sure to import jquery before hand – TrevorTheIntern Jun 20 '14 at 15:47
  • yes. you need to add jquery reference before if you want to use above code. the best you can do is write this code: <script src="../../site assets/jquery1.8.2.min.js"></script> <script> $("input[title='Title']").closest('tr').hide(); </script> save the file with .js extension. upload in any document library and refer this file in content editor web part. – SSS Jun 21 '14 at 17:15
0

In the list settings you can select the content types as on. then select the item content type and hide the column

  • 1
    OP wants to hide a specific column, not a content type – Robert Lindgren Jul 11 '14 at 11:31
0

Maybe I am missing something, but these answers are way more complicated than they need to be.

Just make a custom NewForm.aspx in SharePoint designer, edit it, and delete that field. If you get an error for deleting some mandatory field. Just do inline css style="display:none" to hide the field, though do make sure it is getting a default value. Then set that newform as the default.

It should take you less than two minutes this, and you don't need jQuery, CAML, powershell, whatever...

  • I agree that this is a much better answer than using jQuery in a Content Editor Web Part, but if you make a custom form and down the road additional columns are added to the list, won't you have to modify your form as well? – RJ Cuthbertson Jul 11 '14 at 14:32
  • Using the object model allows SharePoint to manage this field's display without having to move away from using the default form. And I don't think that any of these answers would take more or less time than each other. They're all relatively quick fixes if you know what you're doing. – RJ Cuthbertson Jul 11 '14 at 14:33
0

Here's yet an easier solution: To turn off column in the form: Enable Content Types for the list: go into List Settings, advanced settings, yes to content types, click OK Make the column that you don’t want to see in the form have the content type “hidden”: in List Settings click on Item in the Content Types section. Click on the column you want to hide. For Column Settings select This column is Hidden (will not appear in forms)

  • Deborah, the OP said that he doesn't want the column to be hidden from all forms (New, Edit, View), just from the NewItem form. Your solution would hide the field from all the forms. – Paul Strupeikis Mar 9 '16 at 14:56
0

I found a way for this to work by combining a couple of the suggestions above.

I created a field called "HiddenClock", making it a "Date and Time" field, and lower down selected the radio button option to make it "Date & Time".

I created another field called "SubmitDate", made it a calculated field with the formula: =[HiddenClock].

I went into List, then List Settings , then Advanced Settings, and changed the content types to "Allow management of content types?" select "yes". Click ok.

This puts you back in the Settings page. go to the section called "Content Types", click on "item", then I selected the field called "HiddenClock" and changed the column settings to "Hidden". Click ok.

That seemed to do it The "HiddenClock" field was now hidden in both the "new item" as well as the "edit this list". But because the "SubmitDate" field is a calculated field it doesnt show up on "new item" list but it shows up on the "edit this list".

0

You can use jslink to hide the column on newform. I don't have exact code. Refer this answer for similar requirement : Use CSR/JSLink to hide Fields in New/Edit Form

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.