6

i'm using nicedit js which is is a WYSIWYG editor in my textarea to view html doc, but it still editable, how to set this nicedit to readonly mode, i try to search from its doc but unable to find it, do any one have experience using nicedit,

thanks in advance

Apache
  • 1,796
  • 9
  • 50
  • 72

7 Answers7

7

Here is a helpful jQuery solution that I use with nicEdit:

jQuery('.nicEdit-main').attr('contenteditable','false');
jQuery('.nicEdit-panel').hide();

You can simply change it back to 'true' to make it editable again.

Note: I would consider toggling the div background-color along with this solution.

Douglas.Sesar
  • 4,214
  • 3
  • 29
  • 36
  • 2
    To change the background-color use `jQuery('.nicEdit-main').attr('contenteditable','false').parent().css("background-color", "#EEEEEE")` – Stefan Haberl Oct 11 '13 at 12:08
  • Make sure you put it inside the bkLib.onDomLoaded(function () { where nicEditor is instantiated – ShrapNull Mar 06 '18 at 22:06
3

finally the solution is

var myNicEditor = new nicEditor(); myNicEditor.addInstance('templateContent'); nicEditors.findEditor("templateContent").disable();

Apache
  • 1,796
  • 9
  • 50
  • 72
  • I couldn't make it. Please guide me. I have textarea with name 'area3'. I converted it into niceedit. But even after i replace 'templateContent' in the above code with 'area3', i couldn't make it readonly. Please guide me. – Manoj Mar 04 '11 at 04:54
  • hv u declare the above code inside bkLib.onDomLoaded(function() { } – Apache Mar 04 '11 at 07:46
  • it kind of works because it is disabled but when clicking the textarea it gets enabled again :( – tibi Feb 04 '15 at 11:22
1

With the statement nicEditors.findEditor("TextArea").disable(); niceditor is non editable But

nicEditors.findEditor("TextArea").attr("contentEditable","true");

does not make it editable again

demongolem
  • 9,474
  • 36
  • 90
  • 105
rohan
  • 11
  • 1
1

for me only this worked:

document.getElementsByClassName('nicEdit-main')[0].removeAttribute('contentEditable');
tibi
  • 657
  • 1
  • 10
  • 22
0

function edit(){

a = new nicEditor({fullPanel : true}).panelInstance('area5',{hasPanel : true}); }

function no_edit(){

a.removeInstance('area5');
}

Vitalicus
  • 1,188
  • 13
  • 15
0

I'm going to guess it is a WYSIWYG editor.

Try this...

document.getElementById('nicedit').removeAttribute('contentEditable');
alex
  • 479,566
  • 201
  • 878
  • 984
0

nicEditors.findEditor("TextArea").disable();

above statement will disable the TextArea.

For enabling the TextArea, update the nicEdit.js (see below what to update)

search for disable: function () { this.elm.setAttribute("contentEditable", "false"); }

next to this code add the below code

, enable: function () { this.elm.setAttribute("contentEditable", "true"); }

and in your JavaScript call nicEditors.findEditor("TextArea").enable();