Skip to content

Commit

Permalink
Merge pull request #75 from smartprocure/fix/remove_errors
Browse files Browse the repository at this point in the history
[DRAFT] FIX: update errors properly for remove()
  • Loading branch information
stellarhoof authored Nov 15, 2024
2 parents 2690c33 + 0a458f6 commit 7c574ae
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
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

0 comments on commit 7c574ae

Please sign in to comment.