custom validation inside an enterprise wiki page layout

Steel Contributor

I am working on an enterprise wiki site collection inside sharepoint farm 2013. I have a Date field named "ExpireDate" and i added it inside the EnterpriseWiki.aspx page layout. Here is the markup for the Date field inside the Page Layout:-

 

<SharePoint:DateTimeField FieldName="5597d368-6f9d-4983-84e5-fa48f40a7a3f" runat="server"></SharePoint:DateTimeField>

and here is the Date field rendered inside the Page Layout:-

expiredate.png

Now i want to add a validation, that the expiry date must be >= Today. so i read this article about how i can add custom validation to our page-layout using javascript http://frontendfreaks.com/custom-validation-in-sharepoint-2013-page-layouts/, but the author of the article did not show where we need to add the code.

so in my case i opened the Enterprisewiki.aspx page layout using SP designer, and i added this test script before closing the </asp:Content> tab:-

 

<script type="text/javascript">
Page.ClientScript.RegisterOnSubmitStatement(this.GetType(), "validate_page", " if (!validate()) { return false; }; ");

function validate_page(){ 
    alert("should show just before submitting the page");
    return false; // should prevent the page from been saved..
}
</script>
</asp:Content>

but when i add or edit a wiki page and i click on save the alert will not be shown + the submission will complete. so can anyone advice on how i can add custom validation to a Date field inside our Enterprisewiki.aspx page layout? Thanks in advance for any help.

0 Replies