Skip to content

Commit

Permalink
Fix hiding add button from payment methods when the one is already ch…
Browse files Browse the repository at this point in the history
…osen
  • Loading branch information
TheMilek committed Dec 13, 2024
1 parent 9056b69 commit 13b9397
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/Resources/views/Order/create.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,21 @@
<script src="{{ path('fos_js_routing_js', { callback: 'fos.Router.setData' }) }}"></script>
<script>
$(document).ready(function() {
$('body').on('DOMNodeInserted', '#sylius_admin_order_creation_new_order_payments [data-form-collection="item"]', function() {
$('#sylius_admin_order_creation_new_order_payments [data-form-collection="add"]').hide();
const targetNode = document.querySelector('#sylius_admin_order_creation_new_order_payments');
const observer = new MutationObserver(mutations => {
mutations.forEach(mutation => {
if (mutation.addedNodes.length > 0) {
document.querySelector('#sylius_admin_order_creation_new_order_payments [data-form-collection="add"]').style.display = 'none';
}
if (mutation.removedNodes.length > 0) {
document.querySelector('#sylius_admin_order_creation_new_order_payments [data-form-collection="add"]').style.display = '';
}
});
});
$('body').on('DOMNodeRemoved', '#sylius_admin_order_creation_new_order_payments [data-form-collection="item"]', function() {
$('#sylius_admin_order_creation_new_order_payments [data-form-collection="add"]').show();
observer.observe(targetNode, {
childList: true,
subtree: true,
});
$('#sylius_admin_order_creation_new_order_shipments [data-form-collection="add"]').on('click', function(e) {
Expand Down

0 comments on commit 13b9397

Please sign in to comment.