6

I have created a custom list with 3 below columns.

Name(Single line of text) 
Approved(Radio Yes/No) 
Comments(Multiple line of text)

I have changed the default forms and on Create new item form, i am displaying Name and Approve fields, here users create a new item using this form. Now on Edit Item form I want to display comments field only when the value in field Approved is No. I've heard that there is some xsl way, please let me know if you have any idea on this or any other way to do this.

1
  • Your title says '...No Code'. I assume that means you want to avoid any coding to satisfy the hiding of a field, rather some point and click property setting to indicate the field is hidden - but then your comments request info on how to change the form behavior by modifying XSL code. [Confused].... Jul 16, 2014 at 18:31

7 Answers 7

8

XSLT-approach of modifying list forms:

  • Open SharePoint Designer.

  • Go to Lists and Libraries, then open your list.

  • Then, find "Forms" box, and click "New" button.

  • Select edit form type, make it default edit form, and enter it's name.

enter image description here

Large size screenshot: https://i.stack.imgur.com/N0e3x.png

  • Now click on your new form name. The form editor will be opened. It will look something like this in design mode:

enter image description here

  • Click on the Comments field.

  • Now switch to "Code" tab (on the status bar below the design view of the form).

  • There you will see some XSLT code. The code which corresponds selected item in the design view will be selected too, somewhere inside dvt_1.rowedit xsl:template.

  • Now you should wrap the <tr> element, which shows "Comments" line, with <xsl:if> element. The result code will look something like this:

    <xsl:if test="@Approved = 'Yes'">
    <tr>
        <td width="190px" valign="top" class="ms-formlabel">
            <H3 class="ms-standardheader">
                <nobr>Comments</nobr>
            </H3>
        </td>
        <td width="400px" valign="top" class="ms-formbody">
            <SharePoint:FormField runat="server" id="ff3{$Pos}" ControlMode="Edit" FieldName="Comments" __designer:bind="{ddwrt:DataBind('u',concat('ff3',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Comments')}"/>
            <SharePoint:FieldDescription runat="server" id="ff3description{$Pos}" FieldName="Comments" ControlMode="Edit"/>
        </td>
    </tr>
    
    </xsl:if>
    
  • Now if you save the form, you will get desired result.

enter image description here

Important notice: XSL transformations are performed server-side, so the Comments row will not be hidden/shown dynamically unless you refresh page each time user changes Approved field value.

In some circumstances, static approach will be enough. That depends on the supposed usage scenario.

If it's not, I'd recommend you to use either InfoPath, or JavaScript/jQuery hack. InfoPath is more preferrable solution.

Here is the official article which explains InfoPath conditional formatting functionality:

For JavaScript/jQuery hack, just add a Content Editor WebPart to the list form (it will be even not necessary to create a custom form in SPD) and use jQuery/js. There are some ready-to-use JavaScript libraries, designed for this purpose. As an example, there is SPUtility.js opensource project, which is maintained by Kit Menke:

Also, here is article about how to do it manually:

2
  • Thanks Andrey..but I am facing problem to understand these 2 steps..There you will see some XSLT code. The code which corresponds selected item in the design view will be selected too, somewhere inside dvt_1.rowedit xsl:template. Now you should wrap the <tr> element, which shows "Comments" line, with <xsl:if> element. The result code will look something like this:
    – NotesArt
    Jun 10, 2012 at 14:53
  • @NotesArt, the source code formatting hadn't been applied for some reason, and the code wasn't shown. I've fixed the answer, now all is OK. Jun 11, 2012 at 11:54
1

except for this "Important notice: XSL transformations are performed server-side, so the Comments row will not be hidden/shown dynamically unless you refresh page each time user changes Approved field value." everything works like a charm. is there any possible solution other than this which not include refreshing the page?

1

Please check the following link, all you have to do is enable content types for the list and then decide if you want it to be visible or not in the form http://community.bamboosolutions.com/blogs/bambooteamblog/archive/2013/06/03/how-to-hide-a-sharepoint-list-column-from-a-list-form.aspx

2
  • The link you provided directs the user to select a content type - then they show the selection of a task content type. I don't have a task content type - I only have 'Item' content type, and when I select it, the option for hidden is disabled, and un-selectable. Jul 16, 2014 at 18:46
  • Works in SharePoint Online (2013/Wave 15). Just did it! Spot on and very easy to do. Sep 17, 2014 at 12:06
0

If you are refering about using XSLT in the DataView web part or XSLT View Webpart as part of the XSLT extensions here is an example (the function is available under ddwrt:IfHasRights) http://sharepointjim.wordpress.com/2009/10/19/sharepoint-data-view-conditional-formatting-based-on-user-permissions-ifhasrights/

2
  • Thanks, but I am very new in SharePoint. Could you please explain a bit using the example I gave. Thanks again.
    – NotesArt
    Jun 6, 2012 at 8:46
  • The question has nothing about permissions. IfHasRights merely determines current user's permissions. Jun 6, 2012 at 9:57
0

Its very much easy when u edit the form in InfoPath... Rules can be defined based on which you can hide the fields.

1
  • True, but only available with Enterprise licensing and does not work in all instances depending upon what list type the user is working with, or if they are trying to use managed metadata.
    – Cory
    Jun 6, 2012 at 14:19
0

You can use the 3rd party tool Column/View Permission to manage permissions based on conditions which in your situation is to display comments field only when the value in field Approved is No, with no code.

BTW, I work for this tool's provider and I mentioned our own product because it works for your issue. Hope it helps :)

0

There is actually a very easy, no-code way to do this if you have access to the server (because you have to run this application on the server), and you don't have to create a special content type - you simply tweak the column properties and click save.

You can use Sharepoint Manager and edit just these properties for any field in your list.

Sharepoint Manager Edit Display Properties

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.