Skip to content

Commit

Permalink
Fix adding new created element on sortable collections sonata-project…
Browse files Browse the repository at this point in the history
…#8201

Apply fix as proposed in
sonata-project#8201 (comment)
  • Loading branch information
BA-JBI authored Aug 15, 2024
1 parent 73492af commit c7a0016
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/Resources/views/CRUD/Association/edit_many_script.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -329,17 +329,24 @@ This code manages the many-to-[one|many] association field popup
data: {_xml_http_request: true },
dataType: 'html',
type: 'POST',
success: function(html) {
success: function(html) {
jQuery('#field_container_{{ id }}').replaceWith(html);
var newElement = jQuery('#{{ id }} [value="' + data.objectId + '"]');
if (newElement.is("input")) {
newElement.attr('checked', 'checked');
if (newElement.length) {
if (newElement.is("input")) {
newElement.attr('checked', 'checked');
} else {
newElement.attr('selected', 'selected');
}
} else {
newElement.attr('selected', 'selected');
var selections = jQuery('#{{ id }}').val().split(',');
selections.push(data.objectId);
jQuery('#{{ id }}').val(selections.filter((val) => val.length > 0).join(','));
}
jQuery('#field_container_{{ id }}').trigger('sonata-admin-append-form-element');
}
}
});
{% endif %}
Expand Down

0 comments on commit c7a0016

Please sign in to comment.