Skip to content

Commit d0e493f

Browse files
committed
Rich text editor: readonly mode
#913 (reply in thread)
1 parent e90002a commit d0e493f

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
- When an user requests a page that does not exist (and the site owner did not provide a custom 404.sql file), we now serve a nice visual 404 web page instead of the ugly textual message and the verbose log messages we used to have.
99
- ![screenshot 404](https://github.com/user-attachments/assets/02525f9e-91ec-4657-a70f-1b7990cbe25f)
1010
- still returns plain text 404 for non-HTML requests
11-
11+
- Rich text editor: implement a readonly mode, activated when the field is not editable
12+
-
1213

1314
## v0.35.1
1415
- improve color palette for charts

examples/rich-text-editor/index.sql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ select 'form' as component,
99
'Create' as validate;
1010

1111
select 'title' as name, 'Blog post title' as label, 'My new post' as value;
12-
select 'content' as name, 'textarea' as type, 'Your blog post here' as label, 'Your blog post here' as value, true as required;
12+
select 'content' as name, 'textarea' as type, 'Your blog post here' as label, 'Your blog post here' as value, true as required, $disabled is not null as disabled;
1313

1414
select 'list' as component,
1515
'Blog posts' as title;
1616

1717
select title, sqlpage.link('post', json_object('id', id)) as link
1818
from blog_posts;
19-

examples/rich-text-editor/rich_text_editor.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,13 @@ function getMarkdownToolbarOptions() {
8888
* @param {string} initialValue - The initial content for the editor.
8989
* @returns {Quill} - The initialized Quill instance.
9090
*/
91-
function initializeQuillEditor(editorDiv, toolbarOptions, initialValue) {
91+
function initializeQuillEditor(editorDiv, toolbarOptions, initialValue, readOnly) {
9292
const quill = new Quill(editorDiv, {
9393
theme: "snow",
9494
modules: {
9595
toolbar: toolbarOptions,
9696
},
97+
readOnly: readOnly,
9798
formats: [
9899
"bold",
99100
"italic",
@@ -361,12 +362,14 @@ function setupSingleEditor(textarea, toolbarOptions) {
361362

362363
try {
363364
const initialValue = textarea.value;
365+
const readOnly = textarea.readOnly || textarea.disabled;
364366
const form = textarea.closest("form");
365367
const editorDiv = createAndReplaceTextarea(textarea);
366368
const quill = initializeQuillEditor(
367369
editorDiv,
368370
toolbarOptions,
369371
initialValue,
372+
readOnly,
370373
);
371374
updateTextareaOnSubmit(form, textarea, quill);
372375
textarea.dataset.quillInitialized = "true";

0 commit comments

Comments
 (0)