From d7a197436da2d2d441106185bc6684c2a68d6412 Mon Sep 17 00:00:00 2001 From: JeffJiang Date: Tue, 27 Aug 2019 23:24:56 +0800 Subject: [PATCH] fix: clear previous validation error (#3) * fix: clear previous validation error * chore(npm): version 0.1.0-beta.4 --- example/src/UserForm.tsx | 18 +++++++----------- package.json | 2 +- src/core/FormField.ts | 2 +- tsconfig.json | 2 +- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/example/src/UserForm.tsx b/example/src/UserForm.tsx index 05cc33c6..45e954ad 100644 --- a/example/src/UserForm.tsx +++ b/example/src/UserForm.tsx @@ -9,17 +9,13 @@ export const UserForm = () => { const { errors } = model.getFormField('user'); - const handleSubmit = React.useCallback( - async e => { - e.preventDefault(); - console.log(model); - const valid = await model.validate('user'); - if (valid) { - alert('valid success'); - } - }, - [model], - ); + const handleSubmit = async e => { + e.preventDefault(); + const valid = await model.validate('user'); + if (valid) { + console.info('valid success'); + } + }; return (
diff --git a/package.json b/package.json index b4668754..a71445ea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "stated-form-bean", - "version": "0.1.0-beta.3", + "version": "0.1.0-beta.4", "description": "", "main": "dist/cjs", "module": "dist/es", diff --git a/src/core/FormField.ts b/src/core/FormField.ts index 74a2c6bb..f3f9628f 100644 --- a/src/core/FormField.ts +++ b/src/core/FormField.ts @@ -27,12 +27,12 @@ export class FormField { if (yupSchema === undefined) { throw new Error('miss yup schema for ' + String(this.field)); } + this._clearErrors(); return yupSchema .validate(data, { abortEarly: false, }) .then(() => { - this._clearErrors(); return true; }) .catch(err => { diff --git a/tsconfig.json b/tsconfig.json index b7cd99be..a11f7dd7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,7 +15,7 @@ "paths": { "stated-form-bean": ["src"] }, - "sourceMap": true, + "inlineSourceMap": true, "inlineSources": true, "strict": true, "stripInternal": true,