Skip to content

Commit

Permalink
feat(core): support disable forceClear to clearFormGraph (#3122)
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang authored May 12, 2022
1 parent 9eb7306 commit d24168b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 18 additions & 0 deletions packages/core/src/__tests__/form.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1597,3 +1597,21 @@ test('form clearFormGraph need clear field values', () => {
form.clearFormGraph('*')
expect(form.values.aa).toBeUndefined()
})

test('form clearFormGraph not clear field values', () => {
const form = attach(
createForm({
values: {
aa: '123',
},
})
)
attach(
form.createField({
name: 'aa',
})
)
expect(form.values.aa).toEqual('123')
form.clearFormGraph('*', false)
expect(form.values.aa).toEqual('123')
})
4 changes: 2 additions & 2 deletions packages/core/src/models/Form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,9 +593,9 @@ export class Form<ValueType extends object = any> {
this.graph.setGraph(graph)
}

clearFormGraph = (pattern: FormPathPattern = '*') => {
clearFormGraph = (pattern: FormPathPattern = '*', forceClear = true) => {
this.query(pattern).forEach((field) => {
field.destroy()
field.destroy(forceClear)
})
}

Expand Down

0 comments on commit d24168b

Please sign in to comment.