In a previous post, I explained how you could use a new feature in SharePoint 2013 called Client Side Rendering (CSR) to color code a list view. Using that same methodology, I’ll be going over how you can easily hide a form field based on SharePoint permissions…another one of those things that I’m always asked to implement.
For this specific example, I’ll be hiding the “Assigned To” field on the New Form of a standard Tasks list that will only show it if the current user is a member of the Viewers group, or if the user is a site collection admin…I know the example doesn’t make a lot of sense, but I’m trying to keep it simple. 🙂
To implement this exact solution, follow these steps:
1. Create a standard Tasks list
2. Download the MSS.HidingFormFields.js file
4. Navigate to the Tasks list
5. Click the “List” tab in the ribbon, click the “Form Web Parts” button in the Customize Form group, and select the “Default New Form” button
7. Save the Web Part
Note: the URL for the JSLink property must contain an appropriate SharePoint token.
And if all went well, assuming that you’re not in the Visitors group or a Site Collection Admin, the “Assigned To” field should be hidden on the New Form.
A few things to note:
- I’m using a little jQuery, so to use this solution, you’ll need to make sure that you have jQuery loaded into the page as well. I like to load it onto my Master page so I can do jQuery magic everywhere.
And that’s it! Stay tuned for my next post on creating a document rollup using SharePoint 2013 search…which also uses CSR. 🙂