Question

I'm trying to make a condition such that:

  • If date in field is before current date or equals to current date, user can tick the checkbox
  • Otherwise, any fields with dates after the current date will be made "uneditable"

My XSLT codes are as shown below:

<xsl:template match="/">


        <xsl:variable name="vA"  select="current-date()"/>

        <xsl:template match="/"><FL><xsl:value-of select="format-dateTime($vA, '[M01][D01][Y0001]')"/></FL></xsl:template>

                                <xsl:choose> 

                                    <xsl:when test="@Day_x0020_2&lt;=$vA">


                    <tr align="center">
                        <td width="400px" valign="top" class="ms-formbody">
                            <SharePoint:FormField runat="server" id="ff11{$Pos}" ControlMode="Edit" FieldName="Day_x0020_2" __designer:bind="{ddwrt:DataBind('u',concat('ff11',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Day_x0020_2')}"/>
                            <SharePoint:FieldDescription runat="server" id="ff11description{$Pos}" FieldName="Day_x0020_2" ControlMode="Edit"/> 
                        </td>
                        <td width="400px" valign="top" class="ms-formbody">
                            <SharePoint:FormField runat="server" id="ff12{$Pos}" ControlMode="Edit" FieldName="Day_x0020_2_x0020_Approval" __designer:bind="{ddwrt:DataBind('u',concat('ff12',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Day_x0020_2_x0020_Approval')}"/>
                            <SharePoint:FieldDescription runat="server" id="ff12description{$Pos}" FieldName="Day_x0020_2_x0020_Approval" ControlMode="Edit"/>
                        </td>
                    </tr>

                     </xsl:when> 

                                    <xsl:otherwise>

                <tr align="center">
                        <td width="400px" valign="top" class="ms-formbody">
                            <SharePoint:FormField runat="server" id="ff11{$Pos}" ControlMode="Edit" FieldName="Day_x0020_2" __designer:bind="{ddwrt:DataBind('u',concat('ff11',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Day_x0020_2')}"/>
                            <SharePoint:FieldDescription runat="server" id="ff11description{$Pos}" FieldName="Day_x0020_2" ControlMode="Edit"/>
                        </td>
                        <td width="400px" valign="top" class="ms-formbody">
                            <SharePoint:FormField runat="server" id="ff12{$Pos}" ControlMode="Edit" FieldName="Day_x0020_2_x0020_Approval" __designer:bind="{ddwrt:DataBind('u',concat('ff12',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Day_x0020_2_x0020_Approval')}"/>
                            <SharePoint:FieldDescription runat="server" id="ff12description{$Pos}" FieldName="Day_x0020_2_x0020_Approval" ControlMode="Display"/>
                        </td>
                    </tr>


                 </xsl:otherwise> 
                                </xsl:choose>


 </xsl:template>

The ID '@Day_x0020_2' is the ID of the date shown in the field.

I am trying to compare the date shown in this field with the current date that the user logs in to use this form.

My codes above causes error, and the page cannot be shown. I think there is something wrong with my codes but I cannot figure out what is wrong. Please help me thank you. If anyone has a javascript solution for this, that would be great too.

Was it helpful?

Solution

var date = document.getElementById("Day_x0020_2").value;
var varDate = new Date(date); //dd-mm-YYYY
var today = new Date();

if(varDate >= today) 
{
 //Make fields uneditable with something like below:

  $('.ms-formtable td select,.ms-formtable td input, .ms-formtable td textarea, .ms-formtable td .sp-peoplepicker-topLevel').attr('disabled',true);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top