Opened 10 years ago
Last modified 6 years ago
#16284 assigned enhancement
dojox.json.schema.validate schema type may be constructors
Reported by: | Greg Girty | Owned by: | Kris Zyp |
---|---|---|---|
Priority: | undecided | Milestone: | 1.15 |
Component: | Dojox | Version: | 1.8.1 |
Keywords: | Cc: | ||
Blocked By: | Blocking: |
Description
This is a continuation of the patch submitted for #16279.
This enhances the behavior of dojox.json.schema.validate, it remains compatible with existing tests.
This revision allows the schema.type parameter to be a constructor function. The tested object will pass validation if it is an instance of schema.type.
E.g.
require(['dojo', 'dojox/json/schema'], function(dojo, djs){ /* Sample schema, note the use of Date in the inner 'type' param */ var s = {properties:{foo: {type:'object', optional:false, properties:{bar:{type:['null', Date]}, } } }} /* Sample data */ var tests = [ {expect: false, test: {foo:null} }, {expect: false, test: {foo:{bar:'foo'}} }, {expect: false, test: {foo:{bar:{}}} }, {expect: true, test: {foo:{bar:new Date()}} }, {expect: true, test: {foo:{bar:null}} } ] for(var i in tests){ var res = djs.validate(tests[i].test, s); console.log({expected:tests[i].expect, got:res.valid}); } /* var alt = {properties:{foo: {type:'object', optional:false, properties:{bar:{type:Date, optional:true}, } } }} for(var i in tests){ var res = djs.validate(tests[i].test, alt); console.log({expected:tests[i].expect, got:res.valid}); } */ });
This revision also tests if the schema.type is null or empty string. For these cases, validation fails with an 'invalid schema' feedback.
Attachments (1)
Change History (4)
Changed 10 years ago by
comment:1 Changed 10 years ago by
Component: | General → Dojox |
---|---|
Owner: | set to Kris Zyp |
Status: | new → assigned |
comment:3 Changed 6 years ago by
Milestone: | 1.13 → 1.15 |
---|
Ticket planning... move current 1.13 tickets out to 1.15 to make it easier to move tickets into the 1.13 milestone.
Note: See
TracTickets for help on using
tickets.
validate schema type params can be constructor functions