Fixed error, when creation of new elements is disabled in collectionTypes.

This for example happens if the user does not have the permission to create new elements.
This commit is contained in:
Jan Böhmer 2022-08-04 00:06:22 +02:00
parent 7dfbb4c536
commit b51aa0951e
2 changed files with 17 additions and 4 deletions

View file

@ -38,6 +38,13 @@ export default class extends Controller {
const targetTable = this.targetTarget; const targetTable = this.targetTarget;
const prototype = this.prototypeValue const prototype = this.prototypeValue
if(!prototype) {
console.warn("Prototype is not set, we cannot create a new element. This is most likely due to missing permissions.");
bootbox.alert("You do not have the permsissions to create a new element. (No protoype element is set)");
return;
}
//Apply the index to prototype to create our element to insert //Apply the index to prototype to create our element to insert
const newElementStr = this.htmlDecode(prototype.replace(/__name__/g, this.generateUID())); const newElementStr = this.htmlDecode(prototype.replace(/__name__/g, this.generateUID()));

View file

@ -1,8 +1,14 @@
{% macro controller(form, deleteMessage) %} {% macro controller(form, deleteMessage) %}
{{ stimulus_controller('elements/collection_type', { {% if form.vars.prototype is defined %}
'deleteMessage': deleteMessage|trans, {{ stimulus_controller('elements/collection_type', {
'prototype': form_widget(form.vars.prototype)|e('html_attr') 'deleteMessage': deleteMessage|trans,
}) }} 'prototype': form_widget(form.vars.prototype)|e('html_attr')
}) }}
{% else %} {# If add_element is disabled/forbidden, prototype is not available #}
{{ stimulus_controller('elements/collection_type', {
'deleteMessage': deleteMessage|trans,
}) }}
{% endif %}
{% endmacro %} {% endmacro %}
{% macro target() %} {% macro target() %}