Multi line enhanced rich text I am not able to validate blank or not

Hi Friends,

I am using MultiLine text box (Enhanced Rich Text) field on my NewForm.aspx. I have written client side script on "PreSaveItem" method  to check the multiline tech box is empty or not.But if the rich text even if it having the data alert is showing always required field message. Because I am not able to get the data from enhanced rich text.But for plain text my code is working fine.

Please any one has done enhanced rich text data using client side script.Please help me.

Thanks,

Tiru

June 21st, 2015 4:28pm

Hi,

Instead of PreSaveItem, you can use SharePoint's internal validation mechanism - in which case you don't need to parse the value by yourself. I think SharePoint uses some hidden control to read/parse values from Rich text editor.

Please look at the code example: https://code.msdn.microsoft.com/office/Client-side-rendering-code-80cc9b05

If you would like manually check/parse value (which you shouldn't) then there's JavaScript APIs in 'SP.UI.RTE.js' file - which you explore by yourself.

Free Windows Admin Tool Kit Click here and download it now
June 22nd, 2015 12:45am

Hi Tiru,

Please try below code

var myDivObj = document.getElementById("ctl00_ctl45_g_8c1d7734_8b45_4a52_8155_e1a31b7467ee_ff61_ctl00_RichHtmlField_displayContent");
if ( myDivObj ) {
  var value=myDivObj.innerHTML.replace(/<[\/]{0,1}(p)[^><]*>/ig,"");
  if(value.length>1)
  {
     alert('It is not empty');
  }
  else
  {
  alert('It is empty');
  }
}else{
   alert ( "Something went wrong...Please try again" );
}
Thanks.

June 22nd, 2015 10:30am

Hi Tirupal,

From your description, my understanding is that you have doubt about validate multi-line field in PreSaveItem.

Please try this code below:

<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
function PreSaveAction(){

 if($(".ms-rtestate-write[id^='Action_x0020_Required']")[0].innerHTML=="<p></p>"){
  alert('Please fill out Column B');
  return false;
 }
return true;
}
</script>

Please refer to the screenshot below to get the selector and my test result:

Best Regards,

Vincent Han

Free Windows Admin Tool Kit Click here and download it now
June 23rd, 2015 2:15am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics