Saturday 5 July 2014

SharePoint - Multiple Lines of Text Field and Single Line Text as Disabled or Read-Only

Introduction
Disabled or read-only to multiple lines of a text field and single line text in an edit form in a SharePoint list.

Objective
Use of SharePoint Designer to make a field read only. Here is a method to make a field readonly using jQuery and a Content Editor Web Part.

Edit the EditForm.aspx page
If the Edit Page option is missing from the Site Actions menu then use the ToolPaneView=2 URL parameter.

For example
/EditForm.aspx?ToolPaneView=2Add a Content Editor Web PartAdd the following code (in this example, “Question” is the name of my field):Using the code
$(document).ready(function () {
ConvertTextboxToLable('Title');
ConvertTextareaToLable('Description');
});
//Convert TextArea to Lablefunction ConvertTextareaToLable(colName) {
var txtHTML = $("textarea[Title='" + colName + "']").html();
var tdColumn = $("textarea[Title='" + colName + "']").closest('td');
var tdColumnHTML = $(tdColumn).html();
$(tdColumn).html("<div style='display:none'>'" + tdColumnHTML + "'</div>");
$(tdColumn).append(txtHTML);
}
//Convert Textbox to Lablefunction ConvertTextboxToLable(colName) {
var txtHTML = $("input[type=text][Title='" + colName + "']").val
();
var tdColumn = $("input[type=text][Title='" + colName +
"']").closest('td');
var tdColumnHTML = $(tdColumn).html();
$(tdColumn).html("<div style='display:none'>'" + tdColumnHTML +
"'</div>");
$(tdColumn).append(txtHTML);
} 

Summary
In this article we have several requests for a solution for setting fields as read only in an Edit Form.

No comments:

Post a Comment

SharePoint 2013 - Uploading Multiple Attachments To The New Item On List Using JSOM And REST API

  Introduction In this article, we will explore how we can attach multiple attachments to the new item on list using JSOM and REST API. Ther...