Skip to content

Commit

Permalink
Fix #598 by adding a boolean val typecheck.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kai Dorschner committed Jan 8, 2016
1 parent f8557bb commit 1963b42
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ko.validation.rules['required'] = {
validator: function (val, required) {
var testVal;

if (val === undefined || val === null) {
if (val === undefined || val === null || val === false) {
return !required;
}

Expand Down
5 changes: 5 additions & 0 deletions test/rules-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ QUnit.test('Object is NOT Valid and isValid returns False', function(assert) {
assert.violatesRequiredRule(testObj, '');
});

QUnit.test('Issue #598 - "false" is NOT valid and isValid returns false', function(assert) {
var testObj = ko.observable(false).extend({ required: true });
assert.violatesRequiredRule(testObj, '');
});

QUnit.test('Zero is a valid value for required', function(assert) {
var testObj = ko.observable(0).extend({ required: true });
assert.observableIsValid(testObj, 0);
Expand Down

0 comments on commit 1963b42

Please sign in to comment.