Skip to content

Commit 4b653e6

Browse files
author
Jeremy Dorn
committed
Merge branch 'mazswojejzony-master'
2 parents 118ce8a + 3f463dd commit 4b653e6

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

src/editors/object.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -506,19 +506,40 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({
506506
if(this.editing_json) this.hideEditJSON();
507507
else this.showEditJSON();
508508
},
509+
insertPropertyControlUsingPropertyOrder: function (property, control, container) {
510+
var propertyOrder = this.schema.properties[property].propertyOrder;
511+
if (typeof propertyOrder !== "number") propertyOrder = 1000;
512+
control.propertyOrder = propertyOrder;
513+
514+
for (var i = 0; i < container.childNodes.length; i++) {
515+
var child = container.childNodes[i];
516+
if (control.propertyOrder < child.propertyOrder) {
517+
this.addproperty_list.insertBefore(control, child);
518+
control = null;
519+
break;
520+
}
521+
}
522+
if (control) {
523+
this.addproperty_list.appendChild(control);
524+
}
525+
},
509526
addPropertyCheckbox: function(key) {
510527
var self = this;
511-
var checkbox, label, control;
512-
528+
var checkbox, label, labelText, control;
529+
513530
checkbox = self.theme.getCheckbox();
514531
checkbox.style.width = 'auto';
515-
label = self.theme.getCheckboxLabel(key);
532+
533+
labelText = this.schema.properties[key].title ? this.schema.properties[key].title : key;
534+
label = self.theme.getCheckboxLabel(labelText);
535+
516536
control = self.theme.getFormControl(label,checkbox);
517537
control.style.paddingBottom = control.style.marginBottom = control.style.paddingTop = control.style.marginTop = 0;
518538
control.style.height = 'auto';
519539
//control.style.overflowY = 'hidden';
520-
self.addproperty_list.appendChild(control);
521-
540+
541+
this.insertPropertyControlUsingPropertyOrder(key, control, this.addproperty_list);
542+
522543
checkbox.checked = key in this.editors;
523544
checkbox.addEventListener('change',function() {
524545
if(checkbox.checked) {
@@ -626,7 +647,7 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({
626647
this._super(editor);
627648
},
628649
canHaveAdditionalProperties: function() {
629-
return this.schema.additionalProperties !== false && !this.jsoneditor.options.no_additional_properties;
650+
return (this.schema.additionalProperties === true) || !this.jsoneditor.options.no_additional_properties;
630651
},
631652
destroy: function() {
632653
$each(this.cached_editors, function(i,el) {
@@ -666,7 +687,7 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({
666687
if(this.adding_property) this.refreshAddProperties();
667688
},
668689
refreshAddProperties: function() {
669-
if(this.options.disable_properties || this.jsoneditor.options.disable_properties) {
690+
if(this.options.disable_properties || (this.options.disable_properties !== false && this.jsoneditor.options.disable_properties)) {
670691
this.addproperty_controls.style.display = 'none';
671692
return;
672693
}
@@ -726,7 +747,6 @@ JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({
726747
if(this.cached_editors[i]) continue;
727748
show_modal = true;
728749
this.addPropertyCheckbox(i);
729-
this.addproperty_checkboxes[i].disabled = !can_add;
730750
}
731751

732752
// If no editors can be added or removed, hide the modal button

0 commit comments

Comments
 (0)