Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,12 @@ JSONEditor.AbstractEditor = Class.extend({
isEnabled: function() {
return !this.disabled;
},
isRequired: function() {
if(typeof this.schema.required === "boolean") return this.schema.required;
else if(this.parent && this.parent.schema && Array.isArray(this.parent.schema.required)) return this.parent.schema.required.indexOf(this.key) > -1;
else if(this.jsoneditor.options.required_by_default) return true;
else return false;
},
getDisplayText: function(arr) {
var disp = [];
var used = {};
Expand Down
14 changes: 14 additions & 0 deletions src/editors/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,26 @@ JSONEditor.defaults.editors.select = JSONEditor.AbstractEditor.extend({
self.enum_display[i] = ""+(display[i] || option);
self.enum_values[i] = self.typecast(option);
});

if(!this.isRequired()){
self.enum_display.unshift(' ');
self.enum_options.unshift('undefined');
self.enum_values.unshift(undefined);
}

}
// Boolean
else if(this.schema.type === "boolean") {
self.enum_display = this.schema.options && this.schema.options.enum_titles || ['true','false'];
self.enum_options = ['1',''];
self.enum_values = [true,false];

if(!this.isRequired()){
self.enum_display.unshift(' ');
self.enum_options.unshift('undefined');
self.enum_values.unshift(undefined);
}

}
// Dynamic Enum
else if(this.schema.enumSource) {
Expand Down