Skip to content

Commit

Permalink
Improved massage data to better handle completely free-form nodes.
Browse files Browse the repository at this point in the history
  • Loading branch information
sderickson committed Aug 29, 2014
1 parent 19f340c commit 87a14cd
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 17 deletions.
4 changes: 1 addition & 3 deletions dev/js/treema.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 1 addition & 10 deletions dev/scratch.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,7 @@ <h1>Try Things Out Here</h1>
$(document).ready(function () {

var el = $('#scratch');
var schema = {
$ref: '#/definitions/objectOfObjects',

definitions: {
objectOfObjects: {
type: 'object',
additionalProperties: { $ref: '#/definitions/objectOfObjects' }
}
}
};
var schema = { type: 'object' };
var data = { obj1: { one: {}, two: {} }, obj2: {} };
var options = { schema:schema, data:data };
var treema = el.treema(options);
Expand Down
4 changes: 3 additions & 1 deletion src/base.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1353,15 +1353,17 @@ class TreemaNode

@massageData: (options, workingSchema) ->
# do not allow data or default data to start out invalid with the working schema type, if possible
return unless schemaTypes = workingSchema.type
schemaTypes = workingSchema.type or ['string', 'number', 'integer', 'object', 'array', 'boolean', 'null']
schemaTypes = [schemaTypes] unless $.type(schemaTypes) is 'array'

dataType = $.type(options.data)
defaultDataType = $.type(options.defaultData)

# if the data does not match the schema types
if dataType isnt 'undefined' and dataType not in schemaTypes
options.data = @defaultForType(schemaTypes[0])

# if there's no data or default data that works for the schema, reset it
if dataType is 'undefined' and (defaultDataType is 'undefined' or defaultDataType not in schemaTypes)
options.data = @defaultForType(schemaTypes[0])

Expand Down
4 changes: 1 addition & 3 deletions treema.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 87a14cd

Please sign in to comment.