Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

make ckeditor dynamically toggle readonly state when textarea toggles disabled

Ivan Kuchin108f2fe7097e
diff --git a/frontend/src/app/shared/components/editor/components/ckeditor-augmented-textarea/ckeditor-augmented-textarea.component.ts b/frontend/src/app/shared/components/editor/components/ckeditor-augmented-textarea/ckeditor-augmented-textarea.component.ts
index e97081b1bff..686988a594c 100644
--- a/frontend/src/app/shared/components/editor/components/ckeditor-augmented-textarea/ckeditor-augmented-textarea.component.ts
+++ b/frontend/src/app/shared/components/editor/components/ckeditor-augmented-textarea/ckeditor-augmented-textarea.component.ts
@@ -182,9 +182,7 @@ export class CkeditorAugmentedTextareaComponent extends UntilDestroyedMixin impl
// This is e.g. employed to set the text from outside to reuse the same editor for different languages.
jQuery(this.element).data('editor', editor);
- if (this.readOnly) {
- editor.enableReadOnlyMode('wrapped-text-area-disabled');
- }
+ this.setupMarkingReadonlyWhenTextareaIsDisabled(editor);
if (this.halResource?.attachments) {
this.setupAttachmentAddedCallback(editor);
@@ -242,6 +240,24 @@ export class CkeditorAugmentedTextareaComponent extends UntilDestroyedMixin impl
});
}
+ private setupMarkingReadonlyWhenTextareaIsDisabled(editor:ICKEditorInstance) {
+ const observer = new MutationObserver((_mutations) => {
+ if (this.readOnly !== this.wrappedTextArea.disabled) {
+ this.readOnly = this.wrappedTextArea.disabled;
+ if (this.readOnly) {
+ editor.enableReadOnlyMode('wrapped-text-area-disabled');
+ } else {
+ editor.disableReadOnlyMode('wrapped-text-area-disabled');
+ }
+ }
+ });
+ observer.observe(this.wrappedTextArea, { attributes: true });
+
+ if (this.readOnly) {
+ editor.enableReadOnlyMode('wrapped-text-area-disabled');
+ }
+ }
+
private setLabel() {
const textareaId = this.textareaSelector.substring(1);
const label = jQuery(`label[for=${textareaId}]`);