Skip to content

Commit

Permalink
fix: Fix allValid & values issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Dec 10, 2021
1 parent be6b22d commit 3ef8131
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 8 deletions.
9 changes: 8 additions & 1 deletion packages/core/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@ it('validator.tool', async () => {
expect(validator.errorMessages).toEqual({ });
expect(validator.fieldValid('email')).toBeTruthy();
expect(validator.getForm()).toBeUndefined();
expect(validator.reset()).toBeUndefined();
expect(validator.reset()).toEqual({});
expect(validator.setValues({ email: 'test' })).toBeUndefined();
expect(validator.fieldValid('email')).toBeTruthy();
expect(validator.values.email).toEqual('test');
});

it('validator.tool values test case', async () => {
const validator = new Validator({
initValues: { username: 'user' }
});
expect(validator.values).toEqual({ username: 'user' });
});

it('validator.tool options validate', async () => {
const validator = new Validator({
validate: (value: string) => {
Expand Down
10 changes: 7 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

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions 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

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default class Validator {
this.rules = rules || {};
this.validate = validate;
if (initValues) {
this.values = { ...initValues };
this.initValues = { ...initValues };
}
if (form) {
Expand Down Expand Up @@ -121,6 +122,9 @@ export default class Validator {
* @returns Boolean
*/
allValid() {
for (var key in this.values) {
this.message(key, this.values[key], this.rules[key]);
}
for (let key in this.fields) {
if (this.fieldValid(key) === false) {
return false;
Expand Down

0 comments on commit 3ef8131

Please sign in to comment.