Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: clear previous validation error #3

Merged
merged 3 commits into from
Aug 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个 useCallback 不应该去掉吧?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dan said that it is not necessary 😄

Copy link
Member

@JounQin JounQin Aug 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reference URL, bro?

When event handler changes, the button will not render any, right?

e.preventDefault();
const valid = await model.validate('user');
if (valid) {
console.info('valid success');
}
};
return (
<div>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The div wrapper is redundant.

<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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change this?

"inlineSources": true,
"strict": true,
"stripInternal": true,
Expand Down