Skip to content

feat(Forms): support return messages from onSubmitRequest#7078

Merged
langz merged 5 commits intomainfrom
feat/onsubmitrequest-return-messages-main
Mar 20, 2026
Merged

feat(Forms): support return messages from onSubmitRequest#7078
langz merged 5 commits intomainfrom
feat/onsubmitrequest-return-messages-main

Conversation

@langz
Copy link
Copy Markdown
Contributor

@langz langz commented Mar 19, 2026

Motivation: To be able to display error message or info to user when user tries to submit a form that contains errors.
It could be that the field with the error is far away from the submit button, so that the user may not be able to see the error message for that given field, like in the following example.

Using the functionality added in this PR, the user will be able to see the error message by the submit button.

Reason for not using the same functionality in onSubmit is because onSubmit will never trigger or fire when there's errors in the form, but onSubmitRequest will.

This PR allows onSubmitRequest to return error, warning, info, or customStatus messages (same as onSubmit). These are displayed at the form level via FormStatus. Supports async functions.

  • Updated OnSubmitRequest type to return OnSubmitRequestReturn
  • Handle return value in Provider handleSubmitCall
  • Added docs and demo example
  • Added tests for all message types and error flow transition

Fix or feat?
Genuinely I believe it's a feat, but somehow I would like to include it in the next bugfix release, hehe.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 19, 2026

Branch Preview URL (stable):
https://feat-onsubmitrequest-return.eufemia-e25.pages.dev

https://feat-onsubmitrequest-return.eufemia-e25.pages.dev

Deployment URL (unique):
https://9c1d6fc4.eufemia-e25.pages.dev

https://9c1d6fc4.eufemia-e25.pages.dev

@codesandbox-ci
Copy link
Copy Markdown

codesandbox-ci bot commented Mar 19, 2026

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Allow onSubmitRequest to return error, warning, info, or customStatus
messages (same as onSubmit). These are displayed at the form level via
FormStatus. Supports async functions.

- Updated OnSubmitRequest type to return OnSubmitRequestReturn
- Handle return value in Provider handleSubmitCall
- Added docs and demo example
- Added tests for all message types and error flow transition
@langz langz force-pushed the feat/onsubmitrequest-return-messages-main branch from fce8a8d to 24ee497 Compare March 19, 2026 20:40
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 19, 2026

commit: 9df0147

@langz langz changed the title feat(Forms): support return messages from onSubmitRequest fix(Forms): should support return messages from onSubmitRequest Mar 19, 2026
@langz langz changed the title fix(Forms): should support return messages from onSubmitRequest fix(Forms): support return messages from onSubmitRequest Mar 19, 2026
Copy link
Copy Markdown
Member

@tujoworker tujoworker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice if it would be possible to reuse the same logic/code from what we already have for onSubmit.

langz added 2 commits March 19, 2026 22:22
Reduce duplication between onSubmit and onSubmitRequest result handling
by extracting two shared helpers:
- resolveStateResult: try/catch with Error instance handling
- applySubmitState: conditional setSubmitState for error/warning/info/customStatus
@langz
Copy link
Copy Markdown
Contributor Author

langz commented Mar 19, 2026

Would be nice if it would be possible to reuse the same logic/code from what we already have for onSubmit.

Done so now 🙏

@langz langz changed the title fix(Forms): support return messages from onSubmitRequest feat(Forms): support return messages from onSubmitRequest Mar 20, 2026
@langz langz mentioned this pull request Mar 20, 2026
langz added 2 commits March 20, 2026 10:25
Previously, only error and customStatus were cleared at the start of
handleSubmitCall. Warning and info messages from onSubmitRequest would
persist after a subsequent successful submit because setSubmitState
merges state. Now all four keys are cleared.
@langz langz merged commit b63b9fe into main Mar 20, 2026
12 checks passed
@langz langz deleted the feat/onsubmitrequest-return-messages-main branch March 20, 2026 10:09
tujoworker pushed a commit that referenced this pull request Mar 20, 2026
## [10.101.0](v10.100.1...v10.101.0) (2026-03-20)

### 📝 Documentation

* improve naming docs ([#7020](#7020)) ([b398e5a](b398e5a))

### 🐛 Bug Fixes

* **Field.Date:** add validation error when range start date is after end date ([#7019](#7019)) ([3142120](3142120))
* **Field.Email:** improve error message ([#7034](#7034)) ([7446b9c](7446b9c))
* **Input, Autocomplete:** memoize `icon` for ProgressIndicator ([#7027](#7027)) ([5b69748](5b69748)), closes [#6449](#6449)
* **List:** preserve direct li children in `List.Container` ([#7079](#7079)) ([d86275a](d86275a))
* **Stat.Number:** add missing Number export to barrel index ([#7024](#7024)) ([069e9d0](069e9d0))
* **Stat:** ensure amounts are accessible to screen readers ([#7022](#7022)) ([3131116](3131116))
* update forms validation messages across all locales ([#7043](#7043)) ([7557016](7557016))

### ✨ Features

* **Forms:** support return messages from onSubmitRequest ([#7078](#7078)) ([b63b9fe](b63b9fe))
* **List:** add `List.Card` and `List.ScrollView` ([#7080](#7080)) ([91a04d2](91a04d2))
@tujoworker
Copy link
Copy Markdown
Member

🎉 This PR is included in version 10.101.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

2 participants