9

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.

10 Answers 10

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).

2
  • 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 Commented Jun 20, 2014 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. Commented Jun 20, 2014 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.

1
  • This is what i needed for an existing list. worked like a charm. Commented Feb 21, 2017 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.

2
  • 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 Commented Jun 20, 2014 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. Commented Jun 21, 2014 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
  • 1
    OP wants to hide a specific column, not a content type Commented Jul 11, 2014 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...

2
  • 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? Commented Jul 11, 2014 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. Commented Jul 11, 2014 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)

1
  • 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. Commented Mar 9, 2016 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

0

Try steps in this video, steps below

https://youtu.be/lxAmYT-uQe4?feature=shared

Steps:

  1. Create a conditional text column. This column must have a default value.

  2. Create the column that must conditionally appear depending on whether a user is creating and item OR viewing/editing an item.

  3. Click on the NEW button.

  4. Click on EDIT COLUMNS.

  5. Untick the conditional column in order to HIDE it.

  6. Click on the 3 dots next the column that must conditionally SHOW.

  7. Click on EDIT CONDITIONAL FORMULA

  8. Add the formula "=if([$Title] == '', 'false', 'true')" where Title is the name of your conditional column.

  9. Click Save and Save.

0

So...I asked ChatGPT to:

Write a javascript that hides multiple SharePoint 2013 columns from only the new form

Here is what it spit out and it worked right away.

"To hide multiple columns from the new form in SharePoint 2013 using JavaScript, you can use the following code. This code assumes that you are using the default SharePoint list forms (NewForm.aspx)."

<script type="text/javascript">

// Ensure that the SharePoint script file is loaded
SP.SOD.executeOrDelayUntilScriptLoaded(hideColumns, 'sp.js');

function hideColumns() {
    // Specify the internal names of the columns you want to hide
    var columnsToHide = ['Column1', 'Column2', 'Column3'];

    // Get the current page context
    var context = SP.ClientContext.get_current();
    var web = context.get_web();

    // Get the current list
    var list = web.get_lists().getByTitle('YourListTitle');

    // Get the fields (columns) of the list
    var fields = list.get_fields();

    // Iterate through the columns to hide
    for (var i = 0; i < columnsToHide.length; i++) {
        // Get the field by internal name
        var field = fields.getByInternalNameOrTitle(columnsToHide[i]);

        // Set the field to be hidden in the new form
        field.setShowInNewForm(false);
        field.update();
    }

    // Execute the changes
    context.executeQueryAsync(success, failure);

    function success() {
        console.log('Columns hidden successfully.');
    }

    function failure(sender, args) {
        console.log('Failed to hide columns: ' + args.get_message());
    }
}

</script>

"Make sure to replace 'YourListTitle' with the actual title of your SharePoint list and update the 'columnsToHide' array with the internal names of the columns you want to hide.

You can add this script to your NewForm.aspx page using a Content Editor Web Part or a Script Editor Web Part. Make sure to customize the script according to your specific requirements."

NOTE: I did not go into "Content Types" and hide these columns.

I copied the above script, went to my custom list, clicked on edit page, added a SEWP, and pasted the script.

I am now able to hide the columns in the New Form but still go in and see them in the Edit Form.

Also, on the edit page of the list where I have the above SEWP, I am also using a CEWP to display any attachments as a hyperlink using the file name in the 'Attachments' column instead of just seeing a paper clip.

UPDATE

Alright, so when I implement the above code, it literally hides those columns, for good it seems. When I remove the CEWP, the columns do not show back up. So instead I decided to create a NewForm in SP Designer and give those columns a class="" and then add a SEWP to the NewForm webpart I created and added some CSS: display:none.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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