fix(form): route Ctrl+Enter through onSubmit and stop double-firing on_change#8918
Draft
Mystery01092000 wants to merge 2 commits intomarimo-team:mainfrom
Draft
fix(form): route Ctrl+Enter through onSubmit and stop double-firing on_change#8918Mystery01092000 wants to merge 2 commits intomarimo-team:mainfrom
Mystery01092000 wants to merge 2 commits intomarimo-team:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
…n_change Three related bugs in mo.ui.form are fixed: 1. Ctrl+Enter / Cmd+Enter now routes through the <form>'s onSubmit handler via requestSubmit() instead of calling setValue() directly. This ensures that shouldValidate and clearOnSubmit behave consistently regardless of whether the user clicks the button or uses the keyboard shortcut. 2. Shift+Enter inside an OnBlurredInput no longer bypasses the form wrapper. A shiftKey guard is added to the onKeyDown handler so that Shift+Enter cannot inadvertently commit the input value and skip the form buffer. 3. The wrapped element's on_change callback no longer fires during form submission. form._convert_value() previously called element._update(), which always triggered on_change. A new _update_value() method on UIElement updates the stored value without invoking the callback; form._convert_value() now calls that instead, so on_change fires exactly once (on the form itself) per submission. Fixes marimo-team#8324
d7f3a4a to
4a844ca
Compare
Author
|
recheck |
for more information, see https://pre-commit.ci
manzt
requested changes
Mar 30, 2026
Collaborator
manzt
left a comment
There was a problem hiding this comment.
I pulled this down and tested locally but wasn't able to verify that Bug 3 (the double-fire) is fixed. Wrapping a mo.ui.text(on_change=...) in a form and submitting still fires the element's on_change.
Have you verified these change yourself? Could you share a screen recording or a minimal repro snippet showing the correct behavior?
Contributor
|
Going to move to draft while it needs changes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes three related submit-inconsistency bugs in
mo.ui.formreported in #8324.Bug 1 —
Ctrl+EnterbypassedonSubmitFormPlugin.tsxcalledsetValue(newValue)directly in theonKeyDownhandler, skipping the<form>'sonSubmit. This meantshouldValidateandclearOnSubmitwere silently ignored when using the keyboard shortcut.Fix: Replace
setValue(newValue)withformDiv.current?.requestSubmit(), which routes the keyboard shortcut through the sameonSubmitpath as the button click.Bug 2 —
Shift+Enterbypassed the form wrapperOnBlurredInput'sonKeyDownininput.tsxfiredsetValueon anyEnterkeypress with no modifier check.Shift+Enterinside a wrapped text input would commit the input value directly, completely bypassing the form's buffering layer.Fix: Add a
shiftKeyguard — only plainEnter(noShift) commits the value.Bug 3 — Wrapped element's
on_changefired twice per submissionform._convert_value()calledelement._update(value), which always triggers the element's_on_changecallback. This caused the wrapped element'son_changeto fire unexpectedly during form submission (in addition to the form's ownon_change).Fix: Add
UIElement._update_value()— identical to_update()but without the_on_changecall.form._convert_value()now calls_update_value()so the wrapped element'son_changeonly fires when the element itself is interacted with, not when the form extracts its submitted value.Files changed
frontend/src/plugins/impl/FormPlugin.tsxrequestSubmit()instead of directsetValue()inonKeyDownfrontend/src/components/ui/input.tsxshiftKeyguard inOnBlurredInput.onKeyDownmarimo/_plugins/ui/_core/ui_element.py_update_value()method (silent update, no callback)marimo/_plugins/ui/_impl/input.pyform._convert_valueuses_update_valuenot_updatefrontend/src/plugins/impl/__tests__/FormPlugin.test.tsxtests/_plugins/ui/_impl/test_input.pyTest plan
Ctrl+Entertriggers validation whenshouldValidate=TrueCtrl+Enterclears inputs whenclearOnSubmit=TrueShift+Enterinside a text input does not submit the formsetValueexactly onceon_changedoes not fire on form submissionon_changefires exactly once per submission_update_value()updates value without triggeringon_changeI have read the CLA Document and I hereby sign the CLA