editor.disableReadOnlyMode( 'feature-id' ); is not working in DecoupledEditor

Volk Volk 551 Reputation points
2023-08-11T19:08:35.2566667+00:00

Hi!

The question is simple.

This works:
<script src="~/js/ckeditor5-build-classic/ckeditor.js"></script>
<textarea id="editor_middle">@Model.Description</textarea>

ClassicEditor
			.create( document.querySelector( '#editor_middle' ), {
			} )
			.then( editor => {				
				editor.enableReadOnlyMode( 'my-feature-id' );
			} )
			.catch( err => {
				console.error( err.stack );
			} );

This does not work:
<script src="https://cdn.ckeditor.com/ckeditor5/38.1.0/decoupled-document/ckeditor.js"></script>
<div id="editor_middle">@Model.Description</div>

DecoupledEditor
			.create( document.querySelector( '#editor_middle' ), {
			} )
			.then( editor => {				
				editor.enableReadOnlyMode('feature-id');
			} )
			.catch( err => {
				console.error( err.stack );
			} );

I see only html-tags.

No errors in the console!

The documentation says this:

https://ckeditor.com/docs/ckeditor5/latest/api/module_editor-decoupled_decouplededitor-DecoupledEditor.html#member-isReadOnly

Why doesn't it work?

P.S. I could use Classic Editor, but the text is created in Decoupled Editor and for some reason some html-features does not work when output (readonly) - font color, font size. Therefore, I am trying to first output the text in the same editor in which it was created, but in the readonly version.

Thanks!

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,701 questions
JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
1,019 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Volk Volk 551 Reputation points
    2023-08-11T21:18:44.6466667+00:00

    I localized the problem, but it's kind of a horror. )))

    How is this even understood?

    let editor_middle;
    
          .create(document.querySelector('editor_middle'))
    
    			.then(editor => {
    				//const toolbarContainer = document.querySelector('#toolbar-container');
    				//toolbarContainer.appendChild(editor.ui.view.toolbar.element);
    				editor.enableReadOnlyMode('feature-id');
    				editor_middle = editor;
    			})
    
    			.catch(error => {
    				console.error(error);
    			});
    
    	</script>
    

    Everything works if I insert the data manually into the <div> (what I have in the database).

    <div id="editor_middle" style="background: White;">
    <p>&nbsp;</p><p><span class="text-big" style="color:hsl(0,100%,38%);"><strong>Handheld emperor</strong></span></p><p>&nbsp;</p><p>Handheld emperor</p><p>Nintendo, a Japanese electronics company, started as a <a href="https://en.wikipedia.org/wiki/Hanafuda"><i>hanafuda</i> cards</a> manufacturer in 1889. In the mid-1970s, they entered the early video games market and became famous for their home video and handheld game consoles. Nintendo introduced consoles like <strong>NES</strong>, <strong>SNES</strong>, and <strong>Wii</strong>. But the most revolutionary was for sure the <strong>Game Boy</strong>.</p><p>A countdown of Nintendo handhelds</p><p>
    </div>
    
    

    AAAAAAAAAA

    If I output the same string from the DB from the string property of the model, then I see html.

    <div id="editor_middle" style="background: White;">
        @Model.ProjectProduct.MiddleDescription_en
    </div>
    
    

    BBBBBBBBBBBBBBBB

    What the hell is this?And how to fix it?

    I need to put a line with html from the database in the div.


  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.