Skip to content

Commit

Permalink
fix: Fix reset api error.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Oct 26, 2021
1 parent 6e83c06 commit a59b57c
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ validator.js
[![npm bundle size](https://img.shields.io/bundlephobia/minzip/validator.tool)](https://bundlephobia.com/package/validator.tool)
[![Coverage Status](https://jaywcjlove.github.io/validator.js/coverage/badges.svg)](https://jaywcjlove.github.io/validator.js/coverage/lcov-report)

Lightweight JavaScript form validation, that had minimal configuration and felt natural to use. No dependencies, support UMD. `~712B`
Lightweight JavaScript form validation, that had minimal configuration and felt natural to use. No dependencies, support UMD.

> ⚠️ The [`v1`](https://raw.githack.com/jaywcjlove/validator.js/v1-doc/index.html) version document preview is [here](https://raw.githack.com/jaywcjlove/validator.js/v1-doc/index.html).
Expand Down Expand Up @@ -43,7 +43,7 @@ function Demo() {
<input type="email" name="email" />
<p>
{validator.current.message('email', data.email, {
validate: (val) => /^[A-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(val) ? `The ${val} must be a valid email address.` : ''
validate: (val) => !/^[A-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(val) ? `The ${val} must be a valid email address.` : ''
})}
</p>
</div>
Expand Down
8 changes: 5 additions & 3 deletions packages/core/dist/validator.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/core/dist/validator.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/core/dist/validator.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/core/dist/validator.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,13 @@ export default class Validator {
return this.values;
}
reset = () => {
if (!this.form) return;
this.form.reset();
this.values = this.initValues || {};
this.errorMessages = {};
this.messagesShown = false;
this.fields = {};
if (this.form) {
this.form.reset();
};
return this.initValues;
}
fieldValid = (field: string) => this.fields[field] === true;
Expand Down

0 comments on commit a59b57c

Please sign in to comment.