Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CodeBlock editable not sending ajax content #78

Open
emepetres opened this issue Feb 28, 2025 · 0 comments
Open

CodeBlock editable not sending ajax content #78

emepetres opened this issue Feb 28, 2025 · 0 comments

Comments

@emepetres
Copy link

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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant