Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date with min and max rules #459

Merged
merged 2 commits into from
Nov 12, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Src/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function minMaxValidatorFactory(validatorName) {

// From http://www.w3.org/TR/2012/WD-html5-20121025/common-input-element-attributes.html#attr-input-min,
// if the value is parseable to a number, then the minimum should be numeric
if (!isNaN(comparisonValue)) {
if (!isNaN(comparisonValue) && !(comparisonValue instanceof Date)) {
type = "number";
}

Expand Down
48 changes: 47 additions & 1 deletion Tests/rules-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,29 @@ test('Object is Valid and isValid returns True and min is observable', function
equal(testObj(), 4, 'observable still works');
equal(testObj.isValid(), true, 'testObj is valid');
});

test('Object is Valid and isValid returns True and min is date', function () {
var obj = new Date(2012, 05, 04);
var testObj = ko.observable('')
.extend({ min: new Date(2012, 03, 04) });

testObj(obj);

equal(testObj(), obj, 'observable still works');
equal(testObj.isValid(), true, 'testObj is valid');
});

test('Object is NOT Valid and isValid returns False and min is date', function () {
var obj = new Date(2011, 05, 04);
var testObj = ko.observable('')
.extend({ min: new Date(2012, 03, 04) });

testObj(obj);

equal(testObj(), obj, 'observable still works');
equal(testObj.isValid(), false, 'testObj is not valid');
});

//#endregion

//#region Max Validation
Expand Down Expand Up @@ -227,6 +250,29 @@ test('Object is Valid and isValid returns True and max is observable', function
equal(testObj(), 1, 'observable still works');
equal(testObj.isValid(), true, 'testObj is valid');
});

test('Object is Valid and isValid returns True and max is date', function () {
var obj = new Date(2011, 05, 04);
var testObj = ko.observable('')
.extend({ max: new Date(2012, 03, 04) });

testObj(obj);

equal(testObj(), obj, 'observable still works');
equal(testObj.isValid(), true, 'testObj is valid');
});

test('Object is NOT Valid and isValid returns False and max is date', function () {
var obj = new Date(2013, 05, 04);
var testObj = ko.observable('')
.extend({ max: new Date(2012, 03, 04) });

testObj(obj);

equal(testObj(), obj, 'observable still works');
equal(testObj.isValid(), false, 'testObj is not valid');
});

//#endregion

//#region Min Length Validation
Expand Down Expand Up @@ -1134,4 +1180,4 @@ test('Issue #365 - Correct unique validation behaviour for external values that
equal(testObj.isValid(), true, 'testObj is valid');
});

//#endregion
//#endregion