Skip to content

Commit 122aed9

Browse files
committed
Merge branch 'pr/549'
Closes #549 Conflicts: src/editors/array.js
2 parents 8a154bd + 738b4d4 commit 122aed9

File tree

4 files changed

+111
-96
lines changed

4 files changed

+111
-96
lines changed

demo.html

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ <h2>Options</h2>
9494
<option value='disable_array_add'>Disable array add buttons</option>
9595
<option value='disable_array_reorder'>Disable array move buttons</option>
9696
<option value='disable_array_delete'>Disable array delete buttons</option>
97+
<option value='disable_array_delete_all_rows'>Disable array delete all rows buttons</option>
98+
<option value='disable_array_delete_last_row'>Disable array delete last row buttons</option>
9799
</select>
98100
</div>
99101
</div>
@@ -398,31 +400,31 @@ <h2>Code</h2>
398400
document.getElementById('boolean_options').addEventListener('change',function() {
399401
refreshBooleanOptions();
400402
});
401-
403+
402404
// Get starting value from url
403405
if(window.location.href.match('[?&]value=([^&]+)')) {
404406
window.startval = JSON.parse(LZString.decompressFromBase64(window.location.href.match('[?&]value=([^&]+)')[1]));
405407
}
406-
408+
407409
// Set options from direct link
408410
setTheme((window.location.href.match(/[?&]theme=([^&]+)/)||[])[1] || 'bootstrap2', true);
409-
411+
410412
setIconlib((window.location.href.match(/[?&]iconlib=([^&]*)/)||[null,'fontawesome4'])[1], true);
411-
413+
412414
document.getElementById('object_layout').value = (window.location.href.match(/[?&]object_layout=([^&]+)/)||[])[1] || 'normal';
413415
JSONEditor.defaults.options.object_layout = document.getElementById('object_layout').value;
414-
416+
415417
document.getElementById('show_errors').value = (window.location.href.match(/[?&]show_errors=([^&]+)/)||[])[1] || 'interaction';
416418
JSONEditor.defaults.options.show_errors = document.getElementById('show_errors').value;
417-
419+
418420
var boolean_options = document.getElementById('boolean_options').children;
419421
for(var i=0; i<boolean_options.length; i++) {
420422
if(window.location.href.match(new RegExp('[?&]'+boolean_options[i].getAttribute('value')+'([&=]|$)'))) {
421423
boolean_options[i].selected = true;
422424
}
423425
}
424426
refreshBooleanOptions(true);
425-
427+
426428
reload();
427429
})();
428430
</script>

src/editors/array.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
6767
this.row_cache = [];
6868

6969
this.hide_delete_buttons = this.options.disable_array_delete || this.jsoneditor.options.disable_array_delete;
70+
this.hide_delete_all_rows_buttons = this.hide_delete_buttons || this.options.disable_array_delete_all_rows || this.jsoneditor.options.disable_array_delete_all_rows;
71+
this.hide_delete_last_row_buttons = this.hide_delete_buttons || this.options.disable_array_delete_last_row || this.jsoneditor.options.disable_array_delete_last_row;
7072
this.hide_move_buttons = this.options.disable_array_reorder || this.jsoneditor.options.disable_array_reorder;
7173
this.hide_add_button = this.options.disable_array_add || this.jsoneditor.options.disable_array_add;
7274
},
@@ -393,8 +395,8 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
393395
else if(this.value.length === 1) {
394396
this.remove_all_rows_button.style.display = 'none';
395397

396-
// If there are minItems items in the array, hide the delete button beneath the rows
397-
if(minItems || this.hide_delete_buttons) {
398+
// If there are minItems items in the array, or configured to hide the delete_last_row button, hide the delete button beneath the rows
399+
if(minItems || this.hide_delete_last_row_buttons) {
398400
this.delete_last_row_button.style.display = 'none';
399401
}
400402
else {
@@ -403,13 +405,18 @@ JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({
403405
}
404406
}
405407
else {
406-
// If there are minItems items in the array, hide the delete button beneath the rows
407-
if(minItems || this.hide_delete_buttons) {
408+
if(minItems || this.hide_delete_last_row_buttons) {
408409
this.delete_last_row_button.style.display = 'none';
409-
this.remove_all_rows_button.style.display = 'none';
410410
}
411411
else {
412412
this.delete_last_row_button.style.display = '';
413+
controls_needed = true;
414+
}
415+
416+
if(minItems || this.hide_delete_all_rows_buttons) {
417+
this.remove_all_rows_button.style.display = 'none';
418+
}
419+
else {
413420
this.remove_all_rows_button.style.display = '';
414421
controls_needed = true;
415422
}

0 commit comments

Comments
 (0)