Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question
    
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].... –  barrypicker Jul 16 at 18:31

6 Answers 6

up vote 6 down vote accepted

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: http://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:

share|improve this answer
    
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 '12 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. –  Andrey Markeev Jun 11 '12 at 11:54

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

share|improve this answer

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

share|improve this answer
    
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. –  barrypicker Jul 16 at 18:46

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?

share|improve this answer

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

share|improve this answer
    
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 '12 at 14:19

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/

share|improve this answer
    
Thanks, but I am very new in SharePoint. Could you please explain a bit using the example I gave. Thanks again. –  NotesArt Jun 6 '12 at 8:46
    
The question has nothing about permissions. IfHasRights merely determines current user's permissions. –  Andrey Markeev Jun 6 '12 at 9:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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