Skip to content

Commit

Permalink
Merge pull request vuelidate#126 from Krusen/required-bool-support
Browse files Browse the repository at this point in the history
Support boolean values in required validator
  • Loading branch information
Frizi authored Apr 18, 2017
2 parents d767d8b + 383f1e1 commit 7aa3e04
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/validators/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export { withParams }
// "required" core, used in almost every validator to allow empty values
export const req = value => {
if (Array.isArray(value)) return !!value.length
if (value === undefined || value === null) {
if (value === undefined || value === null || value === false) {
return false
}

Expand Down
8 changes: 8 additions & 0 deletions test/unit/specs/validators/required.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ describe('required validator', () => {
expect(required(null)).to.be.false
})

it('should not validate false', () => {
expect(required(false)).to.be.false
})

it('should validate true', () => {
expect(required(true)).to.be.true
})

it('should validate string only with spaces', () => {
expect(required(' ')).to.be.true
})
Expand Down

0 comments on commit 7aa3e04

Please sign in to comment.