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

FIX: do not have special handling for top level errors #74

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.14.1

- FIX: errors[''] is nothing special, remove special handling for it.

# 0.14.0

- Support form errors via an `ValidationError` on `submit`.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mobx-autoform",
"version": "0.14.0",
"version": "0.14.1",
"description": "Ridiculously simple form state management with mobx",
"type": "module",
"main": "dist/cjs/index.js",
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export default ({
return await configSubmit(form.getSnapshot(), form)
} catch (err) {
if (err instanceof ValidationError) {
state.errors = { '': err.message, ...err.cause }
state.errors = err.cause
}
throw err
}
Expand Down
5 changes: 3 additions & 2 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,6 @@ describe('submit()', () => {
'location.addresses.0.tenants.0': ['invalid format'],
})
expect(form.errors).toEqual({
'': 'My submit failed',
'location.addresses.0.tenants.0': ['invalid format'],
})
expect(form.submitError).toBe('My submit failed')
Expand All @@ -431,6 +430,7 @@ describe('submit()', () => {
const submit = async () => {
throw new ValidationError('My submit failed', {
'location.addresses.0.tenants.0': ['invalid format'],
'': ['top level error'],
})
}
form = Form({ fields: goodFields, value: goodValue, submit })
Expand All @@ -439,10 +439,11 @@ describe('submit()', () => {
expect(form.submit.state.error.message).toBe('My submit failed')
expect(form.submit.state.error.cause).toEqual({
'location.addresses.0.tenants.0': ['invalid format'],
'': ['top level error'],
})
expect(form.errors).toEqual({
'': 'My submit failed',
'location.addresses.0.tenants.0': ['invalid format'],
'': ['top level error'],
})
expect(form.submitError).toBe('My submit failed')
expect(result).toBeUndefined()
Expand Down
Loading