Sharepoint Conditional fields in Edit.aspx

僤鯓⒐⒋嵵緔 提交于 2020-01-01 07:12:08

问题


I would like to display certain meta data fields in the edit form based on the value of a fields.

Example: Users upload a document to the Doclib to be approved by there manager. They are allowed to change the meta data Name,Case No, Location until the item is approved by the manager. Once the item is approved I would like to set Name and Case Number to read only.

What is the best way to meet this requirement?

If approved = yes set Name and Case No = Read only Else do nothing.


I have tried this method for about 5 hours. I believed this may be different for ModerationStatus. Might require something special

print("<xsl:choose>
<xsl:when test="@_ModerationStatus != '0;#approved'">               
<SharePoint:FormField runat="server" id="ff12{$Pos}" ControlMode="Edit" FieldName="Test_x0020_Session" __designer:bind="{ddwrt:DataBind('u',concat('ff12',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Test_x0020_Session')}"/>
<SharePoint:FieldDescription runat="server" id="ff12description{$Pos}" FieldName="Test_x0020_Session" ControlMode="Edit"/>                      
</xsl:when>
<xsl:otherwise>
     <xsl:value-of select="@Test_x0020_Session"></xsl:value-of>
</xsl:otherwise>

");

I can get it to work with the other fields but not ModerationStatus. I have also tried changing it to !='0' and !='Approved' and '0;#Approved'. Is there something I am doing wrong?

Seems like its stuck on 0;#Approved


回答1:


This can be easily solved with SharePoint Designer.

  • You will need to modify EditForm.aspx for your list
  • Hide the default ListFormWebPart (Do not delete it!)
  • Insert custom edit item form (more details...)

Custom form will look exactly the same as the default one, but you will be able to customize it with SharePoint Designer. The code below can be used for default WSS Issues list. It will show Issue title as read-only when Issue Status = Closed.

<xsl:choose>
    <xsl:when test="@Status != 'Closed'">
        <SharePoint:FormField runat="server" id="ff1{$Pos}" ControlMode="Edit" FieldName="Title" __designer:bind="{ddwrt:DataBind('u',concat('ff1',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Title')}"/>
        <SharePoint:FieldDescription runat="server" id="ff1description{$Pos}" FieldName="Title" ControlMode="Edit"/>
    </xsl:when>
    <xsl:otherwise>
        <xsl:value-of select="@Title"></xsl:value-of>
    </xsl:otherwise>
</xsl:choose>

You can apply the same logic for your custom lists or/and requirements.

As usual, you might run to some additional problems. I was not able to get the value of @_ModerationStatus in Data View Web Part. I do not know the exact reason...

Here is a simple workaround:

  1. Create a Column in your Document Library
  2. Create a new in workflow SharePoint Designer.

It should fire when item is changed and copy the value of approval status to newly created column.

You can use the custom column for conditional formatting.




回答2:


Follow Toni's comments but for your _ModerationStatus field use following XSLT function:

<xsl:when test="not(starts-with(@_ModerationStatus,'0'))">


来源:https://stackoverflow.com/questions/360216/sharepoint-conditional-fields-in-edit-aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!