Skip to content

Commit

Permalink
Merge pull request #17 from uxcore/20190402_isnotempty
Browse files Browse the repository at this point in the history
add new method isNotEmptyIncludeFalse
  • Loading branch information
veryStarters committed Apr 19, 2019
2 parents 692451b + 076a6ee commit 6a54346
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions HISTORY.md
@@ -1,4 +1,6 @@
# history
## 0.2.7
* `CHANGED` add new method isNotEmptyIncludeFalse to fix a logic error in isNotEmpty

## 0.2.4

Expand Down
12 changes: 11 additions & 1 deletion src/Validator.js
Expand Up @@ -34,10 +34,20 @@ Validator.isNotEmpty = (value) => {
return true;
}
else {
return !!value;
if (value === false) {
console.error('当您看到本提示时,意味着在您的表单校验代码中存在将boolean值false判断为空的情况(isNotEmpty方法),基础组件将在不久的将来更新这一错误逻辑,请及时联系褚天qili.taoqili进行升级或者使用isNotEmptyIncludeFalse代替')
}
return !!value;
}
}

Validator.isNotEmptyIncludeFalse = (value) => {
if (value === false) {
return true
}
return Validator.isNotEmpty(value)
}

Validator.isNum = (value) => {
return PATTERN.NUM.test(value);
}
Expand Down
3 changes: 3 additions & 0 deletions tests/Validator.spec.jsx
Expand Up @@ -11,6 +11,9 @@ describe('Validator', () => {
expect(Validator.isNotEmpty({})).to.be(false);
expect(Validator.isNotEmpty(0)).to.be(true);
expect(Validator.isNotEmpty(true)).to.be(true);
expect(Validator.isNotEmpty(false)).to.be(false);
expect(Validator.isNotEmptyIncludeFalse(false)).to.be(true);
expect(Validator.isNotEmptyIncludeFalse('')).to.be(false);
});

it('should be able to validate number', () => {
Expand Down

0 comments on commit 6a54346

Please sign in to comment.