Skip to content

Commit

Permalink
Fix #598 - required rule does not validate properly for boolean values
Browse files Browse the repository at this point in the history
Closes #600
  • Loading branch information
Kai Dorschner authored and crissdev committed Jan 25, 2016
1 parent 4e38dfa commit f36ce9a
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dist/knockout.validation-with-locales.js
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ kv.rules['required'] = {
validator: function (val, required) {
var testVal;

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

Expand Down
2 changes: 1 addition & 1 deletion dist/knockout.validation-with-locales.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/knockout.validation-with-locales.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/knockout.validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ kv.rules['required'] = {
validator: function (val, required) {
var testVal;

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

Expand Down
2 changes: 1 addition & 1 deletion dist/knockout.validation.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/knockout.validation.min.js.map

Large diffs are not rendered by default.

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, false);
});

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 f36ce9a

Please sign in to comment.