Make plain multi-line text field read only on New Form - SharePoint 2019 on premise

Cherry P 21 Reputation points
2022-09-19T20:31:28.207+00:00

Hi,

I need to make plain multi-line text field read only using JS/jQuery on a new form in custom list. We need to make few fields read only on SharePoint and pulling the data from other DB. We are using SharePoint 2019 on-premise.

I have tried the below lines and it didn't work.

$("textarea[Title='Notes']").attr("disabled", "disabled");  
$("textarea[title='Notes']").attr("readonly","true").css('background-color','#F6F6F6');   

The below line works for me but only for enhanced rich text field and also the multi-line box is not clickable (disabled). I want to make it just read-only as we are pulling the data from other DB.

$("div[id^='Notes']").attr("contentEditable","false").css('background-color','#F6F6F6');  

I was able to make single line text field (Test) and Date field (Date) read only. Below is my code.

$("input[Title='Test']").attr("readonly","true").css('background-color','#F6F6F6');   
$("input[Title^='Date']").attr("readonly","true").css('background-color','#F6F6F6');  

Any thoughts or suggestions on how I can make plain multi-like text fields read only on a form using JS? Appreciate your help!

Thanks,

SharePoint Server
SharePoint Server
A family of Microsoft on-premises document management and storage systems.
2,217 questions
JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
866 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. RaytheonXie_MSFT 30,996 Reputation points Microsoft Vendor
    2022-09-20T02:36:35.69+00:00

    Hi @Cherry P
    Per my test and research, the sample $("div[id^='Notes']").attr("contentEditable","false").css('background-color','#F6F6F6'); you provided is correct. Because the readonly attribute is only for input tags.

    242781-image.png

    For div tag, contenteditable attribute will control if it is editable. So we are unable to set readonly for a div tag. Please refer to the following document
    https://developer.mozilla.org/en/docs/Web/API/HTMLElement/contentEditable


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    0 comments No comments

  2. Cherry P 21 Reputation points
    2022-09-20T12:40:01.29+00:00

    Thanks, I am good