Rich text editor: readonly mode

https://github.com/sqlpage/SQLPage/discussions/913#discussioncomment-13343491
This commit is contained in:
lovasoa
2025-06-02 20:57:19 +02:00
parent e90002a932
commit d0e493fb13
3 changed files with 7 additions and 4 deletions
+2 -1
View File
@@ -8,7 +8,8 @@
- 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.
- ![screenshot 404](https://github.com/user-attachments/assets/02525f9e-91ec-4657-a70f-1b7990cbe25f)
- still returns plain text 404 for non-HTML requests
- Rich text editor: implement a readonly mode, activated when the field is not editable
-
## v0.35.1
- improve color palette for charts
+1 -2
View File
@@ -9,11 +9,10 @@ select 'form' as component,
'Create' as validate;
select 'title' as name, 'Blog post title' as label, 'My new post' as value;
select 'content' as name, 'textarea' as type, 'Your blog post here' as label, 'Your blog post here' as value, true as required;
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;
select 'list' as component,
'Blog posts' as title;
select title, sqlpage.link('post', json_object('id', id)) as link
from blog_posts;
@@ -88,12 +88,13 @@ function getMarkdownToolbarOptions() {
* @param {string} initialValue - The initial content for the editor.
* @returns {Quill} - The initialized Quill instance.
*/
function initializeQuillEditor(editorDiv, toolbarOptions, initialValue) {
function initializeQuillEditor(editorDiv, toolbarOptions, initialValue, readOnly) {
const quill = new Quill(editorDiv, {
theme: "snow",
modules: {
toolbar: toolbarOptions,
},
readOnly: readOnly,
formats: [
"bold",
"italic",
@@ -361,12 +362,14 @@ function setupSingleEditor(textarea, toolbarOptions) {
try {
const initialValue = textarea.value;
const readOnly = textarea.readOnly || textarea.disabled;
const form = textarea.closest("form");
const editorDiv = createAndReplaceTextarea(textarea);
const quill = initializeQuillEditor(
editorDiv,
toolbarOptions,
initialValue,
readOnly,
);
updateTextareaOnSubmit(form, textarea, quill);
textarea.dataset.quillInitialized = "true";