diff --git a/README.md b/README.md index e9e58db..ce33e6e 100644 --- a/README.md +++ b/README.md @@ -203,9 +203,13 @@ schema.properties.notIn = function(value, badwords) } ``` + +## Browser usage +You can use it in the browser by using [browserify](http://browserify.org/), however if that's too much work just use . There is also an example + + # ideas - - make it work in the browser for client side validation - dependency property making one parameters existance depend on another - more types (phone numbers, credit card, ip address) - more filters (camelcase, encode/unencode) diff --git a/examples/cdn.html b/examples/cdn.html new file mode 100644 index 0000000..e401e52 --- /dev/null +++ b/examples/cdn.html @@ -0,0 +1,30 @@ + + + + https://wzrd.in - schemajs example + + +

See the console and view the source for details

+ + + + + + diff --git a/lib/rules.js b/lib/rules.js index 2b74e9b..177ed62 100644 --- a/lib/rules.js +++ b/lib/rules.js @@ -265,7 +265,7 @@ function isValueEmpty(value) { if (_.isUndefined(value)) { return true; } - var canUseIsEmpty = _.isString(value) || _.isArray(value) || _.isObject(value) || false; + var canUseIsEmpty = _.isString(value) || _.isArray(value) || (_.isObject(value) && !_.isDate(value)) || false; if (canUseIsEmpty) { return _.isEmpty(value); } diff --git a/test/bugs/13-default-date.js b/test/bugs/13-default-date.js new file mode 100644 index 0000000..4bb3f8b --- /dev/null +++ b/test/bugs/13-default-date.js @@ -0,0 +1,20 @@ +describe("bugs", function() { + /*jshint expr:true*/ + var schemajs = (typeof window === 'undefined') ? require('../schema') : window.schema; + var expect = (typeof window === 'undefined') ? require('chai').expect : window.chai.expect; + + // + it("Dates defaulting when not empty (#13)", function() { + var date1 = new Date; + var date2 = new Date(1985, 12); + var schema = schemajs.create({ + dateTime: {type:'date', 'default': date1} + }); + + var input1 = schema.validate({}); + var input2 = schema.validate({dateTime: date2}); + + expect(input1.data.dateTime).to.equal(date1); + expect(input2.data.dateTime).to.equal(date2); + }); +});