0

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.

0
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);
}
  • Hi! The original text displayed in ("Day_x0020_2") is in the format of mm-dd-yyyy. Is there any way to change the code to make it into dd-mm-yyyy? – Denise Dec 18 '17 at 5:58
  • var date=new Date();alert( date.getDate() + '-' + (date.getMonth() + 1) + '-' + date.getFullYear()); – Deepmala Dec 18 '17 at 9:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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