SharePoint 2013 Enhanced or Rich TextBox Validation Using JQuery

sharepoint 2013 rich textbox jquery validation.jpg
Sign up for an Office 365 SharePoint Online Business Subscription


In this article you will learn about the Rich TextBox validation using JQuery in SharePoint 2013.


I observed that the mandatory enhanced/rich text box of SharePoint 2013 doesn’t throw an error when we cut the content from it from the edit/new form and it allows us to save the form without any content in rich text box. The article describes the steps to remove this error.

sharepoint 2013 rich textbox jquery validation
sharepoint 2013 rich textbox jquery validation



Read some SharePoint 2013 tutorials below:

Scenario:
On the new/edit form we have enhanced/rich text which is a mandatory field. If we edit the rich text box and cut the content present inside it, the validation doesn’t work. The issue has been resolved.

Solution:
Need to avoid the div tags and get data alone from multiline textbox field using the following script,

Step-1: Navigate to your SharePoint 2013 site.

Step-2: From this page select the Site Actions | Edit Page.

Edit the page, go to the “Insert” tab in the Ribbon and click the “Web Part” option. In the “Web Parts” picker area, go to the “Media and Content” category, select the “Script Editor” Web Part and press the “Add button”. Read about script editor web part in SharePoint 2016.

Step-3: Once the Web Part is inserted into the page, you will see an “EDIT SNIPPET” link; click it. You can insert the HTML and/or JavaScript as in the following:

<script type=”text/javascript”>
$(document).ready(function()
{
var reg1 = new RegExp(“<div class=\”ExternalClass[0-9A-F]+\”>[^<]*”, “”);
var reg2 = new RegExp(“</div>$”, “”);
var Fieldname = $(“td.ms-formlabel h3.ms-standardheader nobr:contains(‘Field Name’)”).parent().parent().parent().find(“div.ms-inputBox div.ms-rtestate-write”).html().replace(reg1, “”).replace(reg2, “”);
var contenttext = $(“td.ms-formlabel h3.ms-standardheader nobr:contains(‘Field Name’)”).parent().parent().parent().find(“div.ms-inputBox div.ms-rtestate-write”).text();
if (contenttext == “”)
{
$(“td.ms-formlabel h3.ms-standardheader nobr:contains(‘Field Name’)”).parent().parent().parent().find(“div.ms-inputBox div.ms-rtestate-write”).html(Fieldname);
}
});
</script>


Hope this will be helpful.


You May Also like the Following SharePoint Online Tutorials:

About Sagar Pardeshi

I am Developer working on Microsoft Technologies for the past 6+years. I am very much passionate about programming and my core skills are SharePoint, ASP.NET & C#,Jquery,Javascript,REST. I am running this blog to share my experience & learning with the community I am an MCP, MCTS .NET & Sharepoint 2010, MCPD Sharepoint 2010, and MCSD HTML 5,Sharepoint 2013 Core Solutions. I am currently working on Sharepoint 2010, MOSS 2007, Sharepoint 2013,Sharepoint 2013 App Dev, C#, ASP.NET, and SQL Server 2008.

View all posts by Sagar Pardeshi →