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

  • Question

  • 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


    Tiru

    Sunday, June 21, 2015 8:27 PM

Answers

  • 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


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Tuesday, June 23, 2015 6:13 AM
    Moderator

All replies

  • 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.


    Thanks,
    Sohel Rana
    http://ranaictiu-technicalblog.blogspot.com

    Monday, June 22, 2015 4:45 AM
  • 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.


    A'Kumar

    • Proposed as answer by Elena Garcia G Wednesday, February 10, 2016 6:35 PM
    Monday, June 22, 2015 2:29 PM
  • 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


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Tuesday, June 23, 2015 6:13 AM
    Moderator