Skip to content

Commit b473cdb

Browse files
committed
Stop checking validations after a single error
1 parent d5f340b commit b473cdb

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/form.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,26 @@ const Form = forwardRef(({ onSubmit, ...rest }, ref) => {
5555
formInput.setCustomValidity('')
5656
if (!formInput.checkValidity()) return
5757

58-
let _error = null
58+
let error = null
5959
const field = getElement(formInput, fields.current, x => x.field)
6060
const others = fields.current.map(x => x.field)
6161

6262
for (const fn of field.details.validation ?? []) {
6363
try {
6464
let err = await fn(formInput, others)
65-
if (typeof err === 'string') _error = new Error(err)
66-
else if (err instanceof Error) _error = err
65+
if (typeof err === 'string') error = new Error(err)
66+
else if (err instanceof Error) error = err
6767
} catch (err) {
68-
_error = err
69-
break
68+
error = err
7069
}
70+
if (error) break
7171
}
7272

73-
if (_error) {
74-
formInput.setCustomValidity(_error.message)
73+
if (error) {
74+
formInput.setCustomValidity(error.message)
7575
formInput.checkValidity()
7676
} else {
77-
field.details.updateState(_error, formInput.validity)
77+
field.details.updateState(error, formInput.validity)
7878
}
7979
}, [])
8080

0 commit comments

Comments
 (0)