From ea5247be2ba76502158c75724e70e5b62fb3889e Mon Sep 17 00:00:00 2001 From: Matti Tahvonen Date: Fri, 19 Jan 2024 19:19:06 +0200 Subject: [PATCH] Maintain disabled/readOnly mode on refresh See #27 --- src/main/java/org/vaadin/tinymce/TinyMce.java | 9 ++------- .../META-INF/resources/frontend/tinymceConnector.js | 6 +++++- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/vaadin/tinymce/TinyMce.java b/src/main/java/org/vaadin/tinymce/TinyMce.java index 832031b..a7543b7 100644 --- a/src/main/java/org/vaadin/tinymce/TinyMce.java +++ b/src/main/java/org/vaadin/tinymce/TinyMce.java @@ -17,7 +17,6 @@ import com.vaadin.flow.component.AbstractCompositeField; import com.vaadin.flow.component.AttachEvent; -import com.vaadin.flow.component.ClientCallable; import com.vaadin.flow.component.ComponentEventListener; import com.vaadin.flow.component.DetachEvent; import com.vaadin.flow.component.Focusable; @@ -26,10 +25,6 @@ import com.vaadin.flow.component.UI; import com.vaadin.flow.component.dependency.JavaScript; import com.vaadin.flow.component.html.Div; -import com.vaadin.flow.component.textfield.TextField; -import com.vaadin.flow.data.value.ValueChangeMode; -import com.vaadin.flow.dom.DebouncePhase; -import com.vaadin.flow.dom.DomEvent; import com.vaadin.flow.dom.DomEventListener; import com.vaadin.flow.dom.DomListenerRegistration; import com.vaadin.flow.dom.Element; @@ -161,8 +156,8 @@ private void initConnector() { runBeforeClientResponse(ui -> { ui.getPage().executeJs( - "window.Vaadin.Flow.tinymceConnector.initLazy($0, $1, $2, $3, $4)", - rawConfig, getElement(), ta, config, currentValue); + "window.Vaadin.Flow.tinymceConnector.initLazy($0, $1, $2, $3, $4, $5)", + rawConfig, getElement(), ta, config, currentValue, (enabled && !readOnly)); }); } diff --git a/src/main/resources/META-INF/resources/frontend/tinymceConnector.js b/src/main/resources/META-INF/resources/frontend/tinymceConnector.js index 7c0c29c..c5c8563 100644 --- a/src/main/resources/META-INF/resources/frontend/tinymceConnector.js +++ b/src/main/resources/META-INF/resources/frontend/tinymceConnector.js @@ -1,5 +1,5 @@ window.Vaadin.Flow.tinymceConnector = { - initLazy: function (customConfig, c, ta, options, initialContent) { + initLazy: function (customConfig, c, ta, options, initialContent, enabled) { // Check whether the connector was already initialized if (c.$connector) { c.$connector.editor.remove(); @@ -36,6 +36,10 @@ window.Vaadin.Flow.tinymceConnector = { baseconfig['height'] = "100%"; baseconfig['target'] = ta; + + if(!enabled) { + baseconfig['readonly'] = true; + } baseconfig['setup'] = function(ed) { c.$connector.editor = ed;