Skip to content

Commit

Permalink
fix: clear previous validation error (#3)
Browse files Browse the repository at this point in the history
* fix: clear previous validation error

* chore(npm): version 0.1.0-beta.4
  • Loading branch information
foreleven authored and JounQin committed Aug 27, 2019
1 parent 90e54bd commit d7a1974
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
18 changes: 7 additions & 11 deletions example/src/UserForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div>
<form>
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": "stated-form-bean",
"version": "0.1.0-beta.3",
"version": "0.1.0-beta.4",
"description": "",
"main": "dist/cjs",
"module": "dist/es",
Expand Down
2 changes: 1 addition & 1 deletion src/core/FormField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ export class FormField<Values> {
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 => {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"paths": {
"stated-form-bean": ["src"]
},
"sourceMap": true,
"inlineSourceMap": true,
"inlineSources": true,
"strict": true,
"stripInternal": true,
Expand Down

0 comments on commit d7a1974

Please sign in to comment.