New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Collection::allowDelete should still allow deletion of unsaved items #6257
Comments
For me it's logical. The entity is not yet saved, the user can always cancel the added item (entry error for example) |
Simple solution: Look for and replace it by:
See: {% extends '@!EasyAdmin/crud/form_theme.html.twig' %}
{% block collection_entry_row %}
{% set is_array_field = 'EasyCorp\\Bundle\\EasyAdminBundle\\Field\\ArrayField' == form_parent(form).vars.ea_vars.field.fieldFqcn ?? false %}
{% set is_complex = form_parent(form).vars.ea_vars.field.customOptions.get('entryIsComplex') ?? false %}
{% set allows_deleting_items = form_parent(form).vars.allow_delete|default(false) or value is null %}
{% set render_expanded = form_parent(form).vars.ea_vars.field.customOptions.get('renderExpanded') ?? false %}
{% set delete_item_button %}
<button type="button" class="btn btn-link btn-link-danger field-collection-delete-button"
title="{{ 'action.remove_item'|trans({}, 'EasyAdminBundle') }}">
<i class="far fa-trash-alt"></i>
</button>
{% endset %}
<div class="field-collection-item {{ is_complex ? 'field-collection-item-complex' }} {{ not form.vars.valid ? 'is-invalid' }}">
{% if is_array_field|default(false) %}
{{ form_label(form) }}
{{ form_widget(form) }}
{% if allows_deleting_items and not disabled %}
{{ delete_item_button }}
{% endif %}
{% else %}
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button {{ render_expanded ? '' : 'collapsed' }}" type="button" data-bs-toggle="collapse" data-bs-target="#{{ id }}-contents">
<i class="fas fw fa-chevron-right form-collection-item-collapse-marker"></i>
{{ value|ea_as_string_translatable }}
</button>
{% if allows_deleting_items and not disabled %}
{{ delete_item_button }}
{% endif %}
</h2>
<div id="{{ id }}-contents" class="accordion-collapse collapse {{ render_expanded ? 'show' }}">
<div class="accordion-body">
<div class="row">
{{ form_widget(form) }}
</div>
</div>
</div>
</div>
{% endif %}
</div>
{% endblock collection_entry_row %} This trick would allow to delete only unsaved item 😇 |
Maybe @javiereguiluz can add this change without form theme override ? |
Unfortunately @javiereguiluz looks very busy atm, I'm afraid he's not concerned for minor issues right now and focusing only on blocking issue of EA :( |
Describe the bug
When you're editing an entity containing a collection of items that you want prohibit deletion, IMHO, the deletion should still be allowed while the item are added but not yet saved (only client-side).
The text was updated successfully, but these errors were encountered: