collections

This commit is contained in:
Benjamin Dalsass
2025-12-08 10:03:34 +01:00
parent 0d3f7c5f07
commit 9543624a0d
3 changed files with 23 additions and 13 deletions

View File

@@ -11,6 +11,8 @@ class CollectionElement extends HTMLElement {
const collectionHolder = document.querySelector('.'+e.currentTarget.dataset.collectionHolderClass);
const item = document.createElement('div');
const collectionHolderList = collectionHolder.querySelector('[role="list"]');
item.innerHTML = collectionHolder
.dataset
.prototype
@@ -19,7 +21,7 @@ class CollectionElement extends HTMLElement {
collectionHolder.dataset.index
);
collectionHolder.appendChild(item);
collectionHolderList.appendChild(item);
collectionHolder.dataset.index++;
}

View File

@@ -34,6 +34,14 @@ class CollectionBlock extends AbstractTypeFormBlock
return CollectionFormType::class;
}
/**
* @return AbstractFormBlock
*/
public function GetPrototypeBlock(): AbstractFormBlock
{
return $this->oPrototypeBlock;
}
public function EntryDependsOnParent(string $sInputName, string $sParentInputName): AbstractFormBlock
{
$this->oPrototypeBlock->InputDependsOnParent($sInputName, $sParentInputName);

View File

@@ -88,21 +88,21 @@
<collection-element {{ block('widget_container_attributes') }}>
{% for child in form %}
<collection-entry-element>
{{ form_widget(child) }}
{% if allow_delete %}
<button type="button" class="remove_item_link ibo-button ibo-is-regular ibo-is-danger">Supprimer</button>
{% endif %}
</collection-entry-element>
{% endfor %}
{% if allow_add %}
<div style="margin-top: 20px;">
<button type="button" class="add_item_link ibo-button ibo-button ibo-is-regular " data-collection-holder-class="{{ name }}">{{ button_label|dict_s }}</button>
</div>
<button type="button" class="add_item_link ibo-button ibo-button ibo-is-regular " data-collection-holder-class="{{ name }}">{{ button_label|dict_s }}</button>
{% endif %}
<div role="list">
{% for child in form %}
<collection-entry-element>
{{ form_widget(child) }}
{% if allow_delete %}
<button type="button" class="remove_item_link ibo-button ibo-is-regular ibo-is-danger">Supprimer</button>
{% endif %}
</collection-entry-element>
{% endfor %}
</div>
</collection-element>
{%- endblock collection_widget -%}