Skip to content

CodeBlock editable not sending ajax content #78

@emepetres

Description

@emepetres

Hi, I'm trying get the updated contents of an editable CodeBlock, when it is updated, with no luck. I've tried with and without an enclosing Form tag. I've also tried getting content from body and from the form request, same result. With TextArea is working as expected.

Below is a sample code to reproduce the issue:

from fasthtml.common import *
from monsterui.all import *

app, rt = fast_app(hdrs=Theme.blue.headers())


@rt
def index():
    return DivHStacked(
        Div(
            TextArea(
                "Initial area here",
                id="area-editor",
                name="text-editor",
                hx_post="/save-code",
                hx_trigger="change, keyup delay:500ms changed",
            )
        ),
        Form(
            CodeBlock(
                "Initial code here",
                contenteditable="true",
                spellcheck=False,
                id="code-editor",
                name="text-editor",
                hx_post="/save-code",
                hx_trigger="keyup delay:500ms"
            ),
        )
    )


@rt("/save-code")
async def post(req):
    form = await req.form()
    print("FORM:", form)
    code = form.get("text-editor")
    # # body = await req.body()
    # # code = body.decode('utf-8')
    print("CODE:", code)
    return f"{code} Saved!"

serve()

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions