You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

63 lines
2.1 KiB

{% extends 'admin/change_form.html' %}
{% block scripts %}
{{ block.super }}
<style>
.json-view-editor .row .form-group {
display: flex;
align-items: baseline;
}
.json-view-editor .row .form-group label {
margin-bottom: 0;
margin-right: 10px;
}
</style>
<script>
let editor = document.getElementById('id_dates')
let schema_str = window.sc = JSON.parse(editor.value)
$(editor).addClass("hidden")
let json_viewer_div = $(`<div class="json-view-editor" id='date-view-editor'></div>`)
$(editor).parent().append(json_viewer_div)
function init(start_value = []) {
if (window.jsoneditor) {
window.jsoneditor.destroy()
}
window.jsoneditor = new JSONEditor(
json_viewer_div[0], {
theme: 'bootstrap4',
schema: {
type: "array",
format: 'table',
title: ' ',
items: {
type: 'object',
title: 'date',
properties: {
year: {type: 'string', format: 'number'},
month: {type: 'string', format: 'number'},
day: {type: 'string', format: 'number'},
}
},
},
disable_edit_json: true,
disable_properties: true,
disable_array_delete_all_rows: true,
disable_array_delete_last_row: true,
disable_array_reorder: true,
grid_columns: 3,
prompt_before_delete: false,
disable_collapse: true,
startval: start_value
})
window.jsoneditor.on('change', () => {
$(editor).val(JSON.stringify(jsoneditor.getValue()))
})
}
init(schema_str || [])
</script>
{% endblock %}