Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
135
rated 0 times [  140] [ 5]  / answers: 1 / hits: 16350  / 9 Years ago, thu, march 12, 2015, 12:00:00

I have been using summernote editor for a while now and it's working for most of the things I've needed it for. However, I recently wanted it disabled ( not destroyed ) after a user action. After efforts without success, it occurred to me I could use the destroy() method to achieve what I wanted. I noticed that Summernote still turned an already disabled textarea to its editor, with the writing area disabled. Here is what I finally did:



To disable summernote after creating it: I first destroyed it, then disabled the target element, and finally re-initialized it:



    $(.summernoteTarget).destroy();

$(.summernoteTarget).prop('disabled', true );

$(.summernoteTarget).summernote();


And to enable it again, I first destroyed it as before, then enabled the target element, and lastly re-initialized it:



    $(.summernoteTarget).destroy();

$(.summernoteTarget).prop('disabled', false );

$(.summernoteTarget).summernote();


This did the trick with minor problem: when it remains in the 'disabled' state, all the controls are not disabled, only the writing area is. So a user can still , say, drag a file onto the writing area but this raises an error.



Has anyone taken a look at the source of Summernote and can add two methods( disable and enable ) in addition to destroy(), so that we can do something like:



     $(.summernoteTargetElement).disable();
$(.summernoteTargetElement).enable();


Thanks.


More From » jquery

 Answers
43

You can disable or enable editor with API after v0.7.3.



// To disable
$('.summernote').summernote('disable');
// To enable
$('.summernote').summernote('enable');


http://summernote.org/deep-dive/#disable-enable


[#67453] Wednesday, March 11, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kylanalis

Total Points: 438
Total Questions: 85
Total Answers: 102

Location: Barbados
Member since Sun, Nov 27, 2022
1 Year ago
kylanalis questions
Sat, Oct 2, 21, 00:00, 3 Years ago
Tue, Oct 13, 20, 00:00, 4 Years ago
Thu, Feb 13, 20, 00:00, 4 Years ago
Tue, Jan 7, 20, 00:00, 4 Years ago
;