Skip to content

Commit 1963b42

Browse files
author
Kai Dorschner
committed
Fix #598 by adding a boolean val typecheck.
1 parent f8557bb commit 1963b42

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

src/rules.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ko.validation.rules['required'] = {
2424
validator: function (val, required) {
2525
var testVal;
2626

27-
if (val === undefined || val === null) {
27+
if (val === undefined || val === null || val === false) {
2828
return !required;
2929
}
3030

test/rules-tests.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ QUnit.test('Object is NOT Valid and isValid returns False', function(assert) {
1616
assert.violatesRequiredRule(testObj, '');
1717
});
1818

19+
QUnit.test('Issue #598 - "false" is NOT valid and isValid returns false', function(assert) {
20+
var testObj = ko.observable(false).extend({ required: true });
21+
assert.violatesRequiredRule(testObj, '');
22+
});
23+
1924
QUnit.test('Zero is a valid value for required', function(assert) {
2025
var testObj = ko.observable(0).extend({ required: true });
2126
assert.observableIsValid(testObj, 0);

0 commit comments

Comments
 (0)