Make Rich text editor read only

CK editor

Recently we had requirement of adding RichText HTML control in MS CRM for few attributes (add RichText HTML editor in MS CRM ). On implementation of it, client demand to make it read only / editable based on some condition. so that implementation is ..

 CKEDITOR.timestamp = null;
 var Xrm;

 $(document).ready(function () {

 var Xrm = parent.Xrm;
 var voeb_eckdaten = Xrm.Page.getAttribute("description").getValue();
 document.getElementById('editor1').value = voeb_eckdaten;

 CKEDITOR.instances.editor1.on('blur', function () {
 var value = CKEDITOR.instances.editor1.getData();
 Xrm.Page.getAttribute("description").setValue(value);
 });

 });

 // make Description RichText WebResourse Mandatory
 // accourding to SOWEdit field on product
 function MakeRichMandatory() {

 var productId = "";
 var productName = "";
 var sowEdit = "";
 if (window.parent.Xrm.Page.getAttribute("soft_productid") != null) {
 productId = window.parent.Xrm.Page.getAttribute("soft_productid").getValue()[0].id;
 productName = window.parent.Xrm.Page.getAttribute("soft_productid").getValue()[0].name;
 }
 //getting value from ProductEntity SOWEdit field 
 SDK.REST.retrieveMultipleRecords("Product", "$select=soft_sowedit,Name&$filter=ProductId eq guid'" + productId + "'",
 function (results) {
 if (results.length != 0) {

 sowEdit = results[0].soft_sowedit;
 }
 },
 function (error) {
 alert(error.message);
 },
 function () {
 });


 if (sowEdit != null || sowEdit != "") {
 if (sowEdit == true) {
 CKEDITOR.on('instanceReady', function () {
 CKEDITOR.instances.editor1.setReadOnly(false);
 });
 }
 else {
 CKEDITOR.on('instanceReady', function () {
 CKEDITOR.instances.editor1.setReadOnly(true);
 });
 }

 }
 else {
 CKEDITOR.on('instanceReady', function () {
 CKEDITOR.instances.editor1.setReadOnly(true);
 });
 }
 }

Thanks.

Explore more about CK Editor here.

Advertisements

One thought on “Make Rich text editor read only

  1. Pingback: Configure HTML Rich Text Editor in CRM | CRM Practice

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s