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

[DRAFT] FIX: update errors properly for remove() #75

Merged
merged 2 commits into from
Nov 15, 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.2

- FIX: remove() removes all errors, not just the removed field.

# 0.14.1

- FIX: errors[''] is nothing special, remove special handling for it.
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.1",
"version": "0.14.2",
"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 @@ -118,7 +118,7 @@ export default ({
F.unsetOn(node.field, parent[keys.fields])
}
// Clean errors for this field and all subfields
state.errors = omitByPrefixes(dotPath, state.errors)
state.errors = omitByPrefixes([dotPath], state.errors)
},
})
node.path = rootPath
Expand Down
3 changes: 3 additions & 0 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,13 @@ describe('Methods and computeds', () => {
})

it('remove()', () => {
form.validate()
expect(_.size(form.errors)).toBe(2)
form.getField('location.addresses.0.tenants.0').remove()
let tenants = form.getField('location.addresses.0.tenants')
expect(tenants.fields).toEqual([])
expect(tenants.value).toEqual([])
expect(_.size(form.errors)).toBe(1)

tenants.remove()
expect(form.getField('location.addresses.0.tenants')).toBeUndefined()
Expand Down
Loading