Thanks, I am good
Make plain multi-line text field read only on New Form - SharePoint 2019 on premise
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,
2 answers
Sort by: Newest
-
-
RaytheonXie_MSFT 31,606 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 thereadonly
attribute is only forinput
tags.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.