Merge remote-tracking branch 'upstream/master' into feature/strict-mode
Conflicts: README.md
This commit is contained in:
commit
f382307a17
|
@ -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 <https://wzrd.in/>. There is also an example <examples/cdn.html>
|
||||||
|
|
||||||
|
|
||||||
# ideas
|
# ideas
|
||||||
|
|
||||||
- make it work in the browser for client side validation
|
|
||||||
- dependency property making one parameters existance depend on another
|
- dependency property making one parameters existance depend on another
|
||||||
- more types (phone numbers, credit card, ip address)
|
- more types (phone numbers, credit card, ip address)
|
||||||
- more filters (camelcase, encode/unencode)
|
- more filters (camelcase, encode/unencode)
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>https://wzrd.in - schemajs example</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>See the console and view the source for details</p>
|
||||||
|
|
||||||
|
<script type="text/javascript" src="https://wzrd.in/standalone/schemajs@latest"></script>
|
||||||
|
<script>
|
||||||
|
|
||||||
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
|
// Example from the README
|
||||||
|
// NOTE: You'll have to use `window.schemajs`
|
||||||
|
var model = window.schemajs.create(
|
||||||
|
{
|
||||||
|
name: {type:"string", filters:"trim", properties:{max:255}, required:true},
|
||||||
|
email: {type:"email", filters:"trim", required:true},
|
||||||
|
wins: {type:"int", filters:["trim", "toInt"], default:0},
|
||||||
|
average: {type:"float", filters:["trim", "toFloat"], default:0}
|
||||||
|
});
|
||||||
|
|
||||||
|
var form = model.validate({name:" your name ", email:" name@example.com "});
|
||||||
|
console.log(form);
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
|
@ -265,7 +265,7 @@ function isValueEmpty(value) {
|
||||||
if (_.isUndefined(value)) {
|
if (_.isUndefined(value)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
var canUseIsEmpty = _.isString(value) || _.isArray(value) || _.isObject(value) || false;
|
var canUseIsEmpty = _.isString(value) || _.isArray(value) || (_.isObject(value) && !_.isDate(value)) || false;
|
||||||
if (canUseIsEmpty) {
|
if (canUseIsEmpty) {
|
||||||
return _.isEmpty(value);
|
return _.isEmpty(value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
// <https://github.com/eleith/schemajs/pull/13>
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
});
|
Reference in New Issue