diff --git a/lib/assets/javascripts/views/answers/edit.js b/lib/assets/javascripts/views/answers/edit.js index 4e01d7a..a36e8ff 100644 --- a/lib/assets/javascripts/views/answers/edit.js +++ b/lib/assets/javascripts/views/answers/edit.js @@ -13,6 +13,7 @@ const closestUnsavedMessage = jQuery => jQuery.closest('.question-form').find('.unsaved-message'); const questionId = jQuery => jQuery.closest('.form-answer').attr('data-autosave'); const isStale = jQuery => jQuery.closest('.question-form').find('.answer-locking').html().length !== 0; + const isReadOnly = () => $('.form-answer fieldset:disabled').length > 0; /* * A map of debounced functions, one for each input, textarea or select change at any * form with class form-answer. The key represents a question id and the value holds @@ -158,10 +159,14 @@ }; TimeagoFactory.render($('time.timeago')); Tinymce.init({ selector: `.${editorClass}` }); - // Attaches form and tinymce event handlers - // ONLY if fieldset is not DISABLED, i.e. not readonly mode - if ($('.form-answer fieldset:disabled').length === 0) { + if (!isReadOnly()) { + // Attaches form and tinymce event handlers Tinymce.findEditorsByClassName(editorClass).forEach(editorHandlers); formHandlers({ jQuery: $('.form-answer'), attachment: 'on' }); + } else { + // Sets the editor mode for each editor to readonly + Tinymce.findEditorsByClassName(editorClass).forEach((editor) => { + editor.setMode('readonly'); + }); } });