Skip to content

Commit

Permalink
fix(core): fix field validateFirst not working (#3071)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryuurock authored Apr 25, 2022
1 parent 0d15fe9 commit 82af5e1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
45 changes: 45 additions & 0 deletions packages/core/src/__tests__/field.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2107,3 +2107,48 @@ test('destroy field need auto remove initialValues', () => {
expect(form.initialValues.aa).toBeUndefined()
expect(form.values.aa).toBeUndefined()
})

test('validateFirst', async () => {
const form = attach(createForm<any>({
validateFirst: false
}))
const aaValidate = jest.fn(() => 'aaError')
const aa = attach(
form.createField({
name: 'aa',
validateFirst: true,
validator: [
aaValidate,
aaValidate,
]
})
)
await aa.onInput('aa')
const bbValidate = jest.fn(() => 'bbError')
const bb = attach(
form.createField({
name: 'bb',
validator: [
bbValidate,
bbValidate,
],
validateFirst: false,
})
)
await bb.onInput('bb')
const ccValidate = jest.fn(() => 'ccError')
const cc = attach(
form.createField({
name: 'cc',
validator: [
ccValidate,
ccValidate,
],
})
)
await cc.onInput('cc')

expect(aaValidate).toBeCalledTimes(1)
expect(bbValidate).toBeCalledTimes(2)
expect(ccValidate).toBeCalledTimes(2)
})
2 changes: 1 addition & 1 deletion packages/core/src/shared/internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ export const validateToFeedbacks = async (
) => {
const results = await validate(field.value, field.validator, {
triggerType,
validateFirst: field.props.validateFirst || field.form.props.validateFirst,
validateFirst: field.props.validateFirst ?? field.form.props.validateFirst,
context: { field, form: field.form },
})

Expand Down

0 comments on commit 82af5e1

Please sign in to comment.