diff --git a/README.md b/README.md index d41d60b18..dbf0b63e1 100644 --- a/README.md +++ b/README.md @@ -167,6 +167,11 @@ Here are all the available options: The CSS theme to use. See the CSS Integration section below for more info. html + + display_required_only + If true, JSON Editor will only display required JSON properties by default. + false + diff --git a/src/editors/object.js b/src/editors/object.js index d3edd9996..81db18dc9 100644 --- a/src/editors/object.js +++ b/src/editors/object.js @@ -235,12 +235,21 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({ } // If the object should be rendered as a div else { - this.defaultProperties = this.schema.defaultProperties || Object.keys(this.schema.properties); + var includeKeys; + if(this.schema.defaultProperties) { + includeKeys = this.schema.defaultProperties; + } + else if(this.jsoneditor.options.display_required_only && this.schema.required) { + includeKeys = this.schema.required; + } + else { + Object.keys(this.schema.properties); + } // Increase the grid width to account for padding self.maxwidth += 1; - $each(this.defaultProperties, function(i,key) { + $each(includeKeys, function(i,key) { self.addObjectProperty(key, true); if(self.editors[key]) {