Skip to content

Commit

Permalink
Renamed 'severity' in 'validatable' to 'errorSeverity'
Browse files Browse the repository at this point in the history
Removed 'isObservable'-check, because it is not needed anymore.
  • Loading branch information
Hekku2 committed Nov 3, 2016
1 parent e22bcd7 commit 466c0b3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions dist/knockout.validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ kv.configuration = configuration;
// }
// )};
//
if (params && !ko.isObservable(params) && (params.message || params.onlyIf || params.severity)) { //if it has a message, condition, or severity object, then its an object literal to use
if (params && (params.message || params.onlyIf || params.severity)) { //if it has a message, condition, or severity object, then its an object literal to use
return kv.addRule(observable, {
rule: ruleName,
message: params.message,
Expand Down Expand Up @@ -1207,8 +1207,8 @@ ko.extenders['validatable'] = function (observable, options) {
throttleEvaluation : options.throttle || config.throttle
};

observable.error = ko.observable(null); // holds the error message, we only need one since we stop processing validators when one is invalid and has and has a severity of 1
observable.severity = ko.observable(1);
observable.error = ko.observable(null); // holds the error message, we only need one since we stop processing validators when one is invalid and has a severity of 1
observable.errorSeverity = ko.observable(1);

// observable.rules:
// ObservableArray of Rule Contexts, where a Rule Context is simply the name of a rule and the params to supply to it
Expand All @@ -1233,7 +1233,7 @@ ko.extenders['validatable'] = function (observable, options) {
var previousIsValid = observable.__valid__.peek();

observable.error(error);
observable.severity(severity);
observable.errorSeverity(severity);
observable.__valid__(false);

if (previousError !== error && !previousIsValid) {
Expand Down
2 changes: 1 addition & 1 deletion src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@
// }
// )};
//
if (params && !ko.isObservable(params) && (params.message || params.onlyIf || params.severity)) { //if it has a message, condition, or severity object, then its an object literal to use
if (params && (params.message || params.onlyIf || params.severity)) { //if it has a message, condition, or severity object, then its an object literal to use
return ko.validation.addRule(observable, {
rule: ruleName,
message: params.message,
Expand Down
6 changes: 3 additions & 3 deletions src/extenders.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ ko.extenders['validatable'] = function (observable, options) {
throttleEvaluation : options.throttle || config.throttle
};

observable.error = ko.observable(null); // holds the error message, we only need one since we stop processing validators when one is invalid and has and has a severity of 1
observable.severity = ko.observable(1);
observable.error = ko.observable(null); // holds the error message, we only need one since we stop processing validators when one is invalid and has a severity of 1
observable.errorSeverity = ko.observable(1);

// observable.rules:
// ObservableArray of Rule Contexts, where a Rule Context is simply the name of a rule and the params to supply to it
Expand All @@ -68,7 +68,7 @@ ko.extenders['validatable'] = function (observable, options) {
var previousIsValid = observable.__valid__.peek();

observable.error(error);
observable.severity(severity);
observable.errorSeverity(severity);
observable.__valid__(false);

if (previousError !== error && !previousIsValid) {
Expand Down
10 changes: 5 additions & 5 deletions test/validation-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ QUnit.test('message parameter receives params and observable when async', functi

//#region Severity tests

QUnit.module('Severity tests');
QUnit.module('Error Severity tests');

QUnit.test('isValid returns false for warning severity', function(assert) {
var testObj = ko.observable('something').extend({
Expand All @@ -446,7 +446,7 @@ QUnit.test('isValid returns false for warning severity', function(assert) {
});
testObj('');
assert.equal(testObj.isValid(), false);
assert.equal(testObj.severity(), 2, 'Severity should equal severity defined in required-validation');
assert.equal(testObj.errorSeverity(), 2, 'Severity should equal severity defined in required-validation');
});

QUnit.test('default severity is 1', function(assert) {
Expand All @@ -455,7 +455,7 @@ QUnit.test('default severity is 1', function(assert) {
});
testObj('');
assert.equal(testObj.isValid(), false);
assert.equal(testObj.severity(), 1, 'Severity should be 1 when not defined');
assert.equal(testObj.errorSeverity(), 1, 'Severity should be 1 when not defined');
});

QUnit.test('Lowest invalid rule severity is returned', function(assert) {
Expand All @@ -474,7 +474,7 @@ QUnit.test('Lowest invalid rule severity is returned', function(assert) {
});
testObj('test');
assert.equal(testObj.isValid(), false);
assert.equal(testObj.severity(), 2, 'Lowest broken rule severity should be 2');
assert.equal(testObj.errorSeverity(), 2, 'Lowest broken rule severity should be 2');
});

QUnit.test('Lowest invalid rule severity for default severity is returned', function(assert) {
Expand All @@ -486,6 +486,6 @@ QUnit.test('Lowest invalid rule severity for default severity is returned', func
});
testObj('');
assert.equal(testObj.isValid(), false);
assert.equal(testObj.severity(), 1, 'Default severity for broken rule should be 1');
assert.equal(testObj.errorSeverity(), 1, 'Default severity for broken rule should be 1');
});
//#endregion

0 comments on commit 466c0b3

Please sign in to comment.