Opened 10 years ago

Closed 9 years ago

Last modified 9 years ago

#12036 closed Bug (fixed)

Initialize editor in readOnly mode when textarea has readonly attribute

Reported by: Piotrek Koszuliński Owned by: Artur Delura
Priority: Normal Milestone: CKEditor 4.5.0 Beta
Component: General Version:
Keywords: Drupal Cc: wim.leers@…

Description

Initialize editor on:

<textarea readonly></textarea>

Editor should be in readOnly mode. Currently we initialize editor in readOnly mode only when textarea has disabled attribute.

https://github.com/ckeditor/ckeditor-dev/blob/master/core/editor.js#L333-L346

Change History (11)

comment:1 Changed 10 years ago by Piotrek Koszuliński

Status: newconfirmed

comment:2 Changed 10 years ago by Wim Leers

Cc: wim.leers@… added
Keywords: Drupal added

Work-around in Drupal 8 for now: https://drupal.org/node/2275491 — following and tagging this so we don't forget to remove the work-around in Drupal 8.

comment:3 Changed 10 years ago by Tobias Stöckler

Note that per the HTML spec disabled and readonly in theory have a slightly different behavior: While readonly still allows focus to be put inside the textarea and (thus) allows the text to be selected, this is not the case for the disabled attribute. disabled textareas generally appear as greyed out.

Quote from the spec (2): The difference between disabled and readonly is that read-only controls are still focusable, so the user can still select the text and interact with it, whereas disabled controls are entirely non-interactive. (For this reason, only text controls can be made read-only: it wouldn't make sense for checkboxes or buttons, for instances.)

CKEditor currently only supports the readonly behavior (despite reacting to the disabled attribute). So the question would be whether it would make sense to add a separate "disabled" mode which would be triggered by the disabled attribute, and have the current "readOnly" mode actually react only to the disabled attribute? That would be an API change, though, and I don't know how such things are handled here.

Links:

comment:4 in reply to:  3 Changed 9 years ago by Artur Delura

Owner: set to Artur Delura
Status: confirmedreview

Replying to tstoeckler:

Note that per the HTML spec disabled and readonly in theory have a slightly different behavior

In CKEditor we handle both attributes in the same way - see here.

Changes and tests in branch:t/12036.

comment:5 Changed 9 years ago by Tobias Stöckler

Thanks for the update.

Wouldn't it be preferable, though, to introduce a second mode that more closely maps to the native behavior?

comment:6 Changed 9 years ago by Wim Leers

@tstoeckler: that's probably not possible for backwards compatibility reasons.

Thanks for the diff, @a.delura!

The patch looks super simple and good to go, except for a single indentation error?

comment:7 Changed 9 years ago by Piotr Jasiun

Resolution: fixed
Status: reviewclosed

Editor is basically html element in contenteditable mode. In the readOnly mode contenteditable attribute is removed. To support disabled mode every HTML element, editor can be build on, should support disabled attribute.

I rebased this ticket on the newest major, pushed small changes and closed it: git:b709b28.

comment:8 Changed 9 years ago by Piotrek Koszuliński

To support disabled mode every HTML element, editor can be build on, should support disabled attribute.

Alternatively, we would need to imitate the disabled mode which seems to be possible, but that would require another ticket, because such feature would need to be implemented separately (as a plugin). I'm not also sure whether having such feature would be worth the effort.

I rebased this ticket on the newest major, pushed small changes and closed it: ​git:b709b28.

Couldn't we make the code nicer (shorter horizontally) by caching editor.element in a variable before this line?

comment:9 in reply to:  8 Changed 9 years ago by Piotr Jasiun

Couldn't we make the code nicer (shorter horizontally) by caching editor.element in a variable before this line?

We could. In fact we could put it here and whole onConfigLoaded refactor this way. But there are a lot of code style changes we could do to make this method looks better.

comment:10 Changed 9 years ago by Piotr Jasiun

And in the isEditorReadOnly method any line is not longer then 120 character so making it shorter horizontally and longer vertically is the matter of taste.

comment:11 Changed 9 years ago by Wim Leers

Yay, this means we'll be able to close https://www.drupal.org/node/2276187 when we upgrade to CKEditor 4.5 :)

Note: See TracTickets for help on using tickets.
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy