0

I'm trying to make specific rich text areas within a list edit form 'read only' based upon the overall status of the list item.

In order to do this I've tried to use the following:

$("textarea[Title='What']").attr("disabled", "disabled");

Within IE the textarea always appears as editable. I think this may be down to the 'rich text' toolbar loading after my attempt to disable but I'm unsure how to get around this.

I would appreciate any suggestions or solutions to this issue.

Thanks.

2
  • Are you trying to disable the control, or hide the control? Jun 16, 2014 at 14:00
  • Disable so that it is still visible but not editable.
    – uint32
    Jun 16, 2014 at 14:09

3 Answers 3

1

Try this:

  • to disable the textarea

    $("textarea[title^='What']").attr('disabled', 'disabled');
    
  • to hide

    $("textarea[title^='What']").css('display', 'none !important');
    
  • or

    $("textarea[title^='What']").parent().find("iframe").hide(); 
    $("textarea[title^='What']").css('display', 'block !important');
    $("textarea[title^='What']").attr('disabled', 'disabled');
    
2
  • The rich textarea is still active within IE, however it is disabled within Chrome. As the rich text menubar isn't given in Chrome I can't help but think that it's related.
    – uint32
    Jun 16, 2014 at 14:17
  • In IE, the the original textarea gets hidden then the content of the textarea is loaded into an iframe (which has a WYSIWYG editor). Therefore the CSS is not applied to the iframe. You may have to strip the html of the original textarea. See the edited answer.
    – Aveenav
    Jun 16, 2014 at 14:40
0

To remove resize in textarea, use resize:none CSS:

https://stackoverflow.com/questions/5235142/how-to-disable-resizable-property-of-textarea

To disable it, use disabled attribute:

http://www.w3schools.com/tags/att_textarea_disabled.asp

Also, be aware that client side can be messed with:

You can try doing it on $(document).ready() or $(window).load() to make sure other scripts have finished.

1
  • $(document).ready() may run before all SP scripts are loaded. Jun 16, 2014 at 16:49
0

In order to create a clean read only output for the user in multiple browsers the following needs to be performed:

  1. Hide the textarea, shown by non IE browsers. This textarea could simply be disabled and left visible but it contains HTML tags generated during rich text edit, not clean output.
  2. Hide the Rich Text Editor toolbar, shown within IE.
  3. Hide the Rich Text Editor window, shown within IE.
  4. Hide the link shown within non IE browsers that describes entry of basic HTML formatting.
  5. If required hide the text description of the output, you may not wish to show the description of entry field.
  6. Add the output of the textarea in place of all the above elements.

It's important that the elements are hidden rather than removed as they will be required upon form submission.

The following function takes the title of a textarea and will achieve all of the above steps. It can be modified as necessary to leave descriptions etc.

function DisableTextArea(title) {  
    // Hide the textarea and get it's content, note that the content comes formatted with HTML tags.
    var newOutput = $("textarea[title='"+ title +"']").hide().val();  

    // Add text area content to the parent tag for the area. This provides a read only output of the text area.
    $("textarea[Title='"+ title +"']").closest("span").append( newOutput );  

    // Hide the rich text editor toolbar.
    $("textarea[Title='"+ title +"']").closest("span").find("table[id$='_toolbar']").hide();

    // Hide the rich text editor window.
    $("textarea[Title='"+ title +"']").closest("span").find("iframe[title='Rich Text Editor']").hide();

    // Hide the link to HTML editing info, visible within non IE browser.
    $("textarea[Title='"+ title +"']").closest("span").parent("span").find("span.ms-formdescription").hide();

    // Hide any text within the parent div, as entry isn't allowed we don't need the text describing input.
    $("textarea[Title='"+ title +"']").closest("td").contents().filter(function(){
        return(this.nodeType == 3);
    }).remove();    
}

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.