0

I'd like to hide 'Multiple Lines of Text' (Enhanced Rich Text) field if it's empty, if isn't empty -> show (both for New form & Edit form).

My code:

 
 if($("input[title^='EnhancedRichTextFieldName']").val() == ""){
    $('nobr:contains("EnhancedRichTextFieldName")').closest('tr').hide()
  } else {
    $('nobr:contains("EnhancedRichTextFieldName")').closest('tr').show();
         }  

It isn't working and I can't find why. I also tried the 'textarea' tag which should be AFAIK only for the 'Plain Text Field' and it also works perfectly for any other types of fields e.g. 'Single Line of Text', 'Multiple Lines of Text (Plain Text)', Choice (drop-down):

if($("input[title^='SingleLineOfTextFieldName']").val() == "")
if($("textarea[title^='PlainTextFieldName']").val() == "")
if($("select[title^='DropDownName']").val() == "") //+ change function

Any idea how to make it works for the Enhanced Rich Text?

Many thanks!

1 Answer 1

0

SharePoint does not create input or textarea for Multiple lines of text(enhanced rich text) field. all the contents of field are within the div. You can get that div by following selector:

var containingDiv = $("div[id^='MultiLineColName']");

So you can hide this div by applying CSS to "display:none" using jQuery.

I found similar question here and here. This may help you.

2
  • Thanks Ganesh, I'll check that. I don't have a problem in hiding 'Enhanced Rich Text' the "nobr:contains" works, I am fighting with the if statement: if($("div[id^='EnhancedRichTextFieldName']").val() == "") to check if it's empty or not
    – Bara Sretr
    Oct 17, 2018 at 8:34
  • 1
    I've find the solution here: if($(".ms-rtestate-write[id^='EnhancedRichTextFieldName']")[0].innerHTML=="<p>​</p>")
    – Bara Sretr
    Oct 17, 2018 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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