Skip to content

Commit

Permalink
Allow validation params in object without custom message and without …
Browse files Browse the repository at this point in the history
…onlyIf

Closes #554
Closes #561
  • Loading branch information
codethug authored and crissdev committed Aug 22, 2018
1 parent e0b8985 commit 8e0846e
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 7 deletions.
3 changes: 2 additions & 1 deletion dist/knockout.validation-with-locales.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,8 @@ kv.configuration = configuration;
// }
// )};
//
if (params && (params.message || params.onlyIf)) { //if it has a message or condition object, then its an object literal to use
//if it has an embedded params, a message or condition object, then it's an object literal to use
if (params && (params.params || params.message || params.onlyIf)) {
return kv.addRule(observable, {
rule: ruleName,
message: params.message,
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.

3 changes: 2 additions & 1 deletion dist/knockout.validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,8 @@ kv.configuration = configuration;
// }
// )};
//
if (params && (params.message || params.onlyIf)) { //if it has a message or condition object, then its an object literal to use
//if it has an embedded params, a message or condition object, then it's an object literal to use
if (params && (params.params || params.message || params.onlyIf)) {
return kv.addRule(observable, {
rule: ruleName,
message: params.message,
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.

3 changes: 2 additions & 1 deletion src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@
// }
// )};
//
if (params && (params.message || params.onlyIf)) { //if it has a message or condition object, then its an object literal to use
//if it has an embedded params, a message or condition object, then it's an object literal to use
if (params && (params.params || params.message || params.onlyIf)) {
return ko.validation.addRule(observable, {
rule: ruleName,
message: params.message,
Expand Down
11 changes: 11 additions & 0 deletions test/validation-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ QUnit.test('Custom Message Correctly appears', function(assert) {
assert.observableIsNotValid(testObj, '', 'This Message is Special');
});

QUnit.test('Allow validation params in object without custom message and without onlyIf', function(assert) {
var testObj = ko.observable('something').extend({
minLength: {
params: 9
// no custom message, no onlyIf
}
});
testObj("short");
assert.violatesMinLengthRule(testObj, "short", 9);
});

//#endregion

//#region Anonymous Rule Validation
Expand Down

0 comments on commit 8e0846e

Please sign in to comment.