editor.js icon indicating copy to clipboard operation
editor.js copied to clipboard

can we display placeholder only when editor.js is not in readonly mode

Open MussaratAziz opened this issue 1 year ago • 5 comments

can we display editor.js placeholder only when editor.js is not in readonly mode?

const editor = new EditorJS({
  ...
  
  placeholder: 'Let`s write an awesome story!'   <----- only display when readOnly is false.

  ...
});

Thank you.

MussaratAziz avatar Sep 26 '23 20:09 MussaratAziz

Makes so much sense

bekogeko avatar Sep 27 '23 07:09 bekogeko

I'm currently having an issue (v 2.29.0) where when I put the editor as readOnly mode, an empty paragraph is added at the top of the editor. image

This is even the case when I don't add placeholder to my config. When I do add it, the message is added after data-placeholder, but it's not shown in the editor itself. And putting the placeholder to false, also doesn't help with this.

When turning off readOnly mode, the bug is gone as well. So it's only a readOnly issue.

I've replicated the bug in a code sandbox here: Edit Editor JS (forked)

timsun28 avatar Jan 26 '24 10:01 timsun28

I'm currently having an issue (v 2.29.0) where when I put the editor as readOnly mode, an empty paragraph is added at the top of the editor.

I have the same bug

kokamvd avatar Feb 28 '24 21:02 kokamvd

For time being I have implemented a workaround for it to remove empty paragraph blocks from the editor when it is in readOnly mode. Below is the function which we can pass in Editor instance to remove empty paragraphs from the editor js.

onReady: ()=>{
                    if(readOnly){
                        const array = document.getElementsByClassName('ce-paragraph')
                        const elementsArray = [...array]; 
                        const elementsTobeRemoved = elementsArray.filter(p => p.innerHTML === '')
                        elementsTobeRemoved.map(element => element.remove())
                    }
                }

OmkarShinde1996 avatar May 04 '24 16:05 OmkarShinde1996

I have switched to a different package for my project that met my requirements better, but it seems like there is an open pr right now that would fix this issue.

timsun28 avatar May 04 '24 17:05 timsun28