Skip to content

Commit

Permalink
Add display_required_only option to editor
Browse files Browse the repository at this point in the history
  • Loading branch information
DRuggeri committed May 25, 2016
1 parent 3556159 commit c7e2a78
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -167,6 +167,11 @@ Here are all the available options:
<td>The CSS theme to use. See the <strong>CSS Integration</strong> section below for more info.</td>
<td><code>html</code></td>
</tr>
<tr>
<td>display_required_only</td>
<td>If <code>true</code>, JSON Editor will only display required JSON properties by default.</td>
<td><code>false</code></td>
</tr>
</tbody>
</table>

Expand Down
13 changes: 11 additions & 2 deletions src/editors/object.js
Expand Up @@ -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]) {
Expand Down

0 comments on commit c7e2a78

Please sign in to comment.