How do you make a ckeditorClassic (textarea field) read only.
How do you make a ckeditorClassic (textarea field) read only.
I have an administration form for managing comments. To act on a comment the admin should first read the comment. In order to properly read it I have ckeditorClassic type enabled, otherwise it will be a challenge because of all the html markup.
The administrator should not be able to edit the comment, only approve/disapprove. Both 'readonly' and 'ckeditorClassic' share text type thus they are mutually incompatible.
In another thread I found attr and tried it:
{
label: 'Comment',
name: 'blog_comments.comment',
type: 'textarea',
type: 'ckeditorClassic',
attr:{ disabled:true },
},
Does attr not work in this instance or do I have the formatting wrong?
Answers
I think you can use the
initEdit
event and usedisable()
in the event to disable the field. Maybe something like this:Kevin
To the html file I added it as:
editor
.on( 'postCreate postRemove', function () {
table.ajax.reload( null, false );
} )
.on( 'initCreate', function () {
editor.field( 'blog_comments.rowOrder' ).enable();
} )
.on( 'initEdit', function () {
editor.field( 'blog_comments.rowOrder' ).disable();
editor.disable('blog_comments.comment');
} );
} );
Other than graying out the text it is still editable - and the edits save.
This example from this thread should help - it's disabling the Age field on edit, but it's writable on creation.
The key code is:
Colin
I do appreciate the pointers however it still isn't working. Here is the code with the previous attempt commented out:
Just to see, I switched enable to disable in the create action if; didn't expect any impact and wasn't disappointed.
Are there any corresponding changes I might make in the controller file?
I don't use CKEditor but it looks like this might be the way to make it read only:
https://ckeditor.com/docs/ckeditor4/latest/features/readonly.html
Maybe something like this will work::
The plugin uses this
conf._editor = CKEDITOR.replace( id, conf.opts );
when opened so I'm guessing you can useopts
to pass the readOnly option.Kevin
I appreciate the assistance yet it remains editable. I'm fairly certain that I can do some jerry-rigging in the php controller file to, essentially, restore a comment to previous saved text, however those hacks can be ugly. Any other ideas?
Hello,
any solution of this case?
Danny
This here worked for me : https://github.com/ckeditor/ckeditor5/issues/1886 - it needs
set,
Colin
Hi @colin
Sorry for my very late reply
where to put that code? Need advise, thank you
Danny
I forgot myself and had to go back over it! It's in the ckEditor plugin code, something like this:
Colin