Skip to content

Commit

Permalink
Merge b1173ba into 5fc98ac
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaolins committed Dec 19, 2018
2 parents 5fc98ac + b1173ba commit 75c39a9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
16 changes: 15 additions & 1 deletion __tests__/number.spec.js
Expand Up @@ -29,7 +29,21 @@ describe('number', () => {
});
});

it('works for no-required', (done) => {
it('works for no-required in case of empty string', (done) => {
new Schema({
v: {
type: 'number',
required: false,
},
}).validate({
v: '',
}, (errors) => {
expect(errors).toBeFalsy();
done();
});
});

it('works for required', (done) => {
new Schema({
v: {
type: 'number',
Expand Down
3 changes: 3 additions & 0 deletions src/validator/number.js
Expand Up @@ -15,6 +15,9 @@ function number(rule, value, callback, source, options) {
const errors = [];
const validate = rule.required || (!rule.required && source.hasOwnProperty(rule.field));
if (validate) {
if (value === '') {
value = undefined;
}
if (isEmptyValue(value) && !rule.required) {
return callback();
}
Expand Down

0 comments on commit 75c39a9

Please sign in to comment.