Merge pull request #406 from creative-commoners/pulls/4/js-fix

FIX Prevent popping open cms-menu when using nested gridfield
This commit is contained in:
Guy Sartorelli 2024-06-25 09:13:23 +12:00 committed by GitHub
commit 1b198466fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -550,34 +550,30 @@
data[parts[0]] = parts[1]; data[parts[0]] = parts[1];
} }
} }
$.ajax({ fetch($(this).attr('data-url'), {
type: 'POST', method: 'POST',
url: $(this).attr('data-url'), body: JSON.stringify(data),
data: data,
headers: { headers: {
'X-Pjax': pjaxTarget 'X-Pjax': pjaxTarget
}, }
success: function(data) { })
.then(response => response.json())
.then(data => {
if (data && data[pjaxTarget]) { if (data && data[pjaxTarget]) {
gridField.find(`[data-pjax-fragment="${pjaxTarget}"]`).replaceWith(data[pjaxTarget]); gridField.find(`[data-pjax-fragment="${pjaxTarget}"]`).replaceWith(data[pjaxTarget]);
} }
}
}); });
} }
else { else {
$(this).closest('tr').next('.nested-gridfield').show(); $(this).closest('tr').next('.nested-gridfield').show();
$.ajax({ fetch($(this).attr('data-toggle')+'1');
url: $(this).attr('data-toggle')+'1'
});
} }
$(this).removeClass('font-icon-right-dir'); $(this).removeClass('font-icon-right-dir');
$(this).addClass('font-icon-down-dir'); $(this).addClass('font-icon-down-dir');
$(this).attr('aria-expanded', 'true'); $(this).attr('aria-expanded', 'true');
} }
else { else {
$.ajax({ fetch($(this).attr('data-toggle')+'0');
url: $(this).attr('data-toggle')+'0'
});
$(this).closest('tr').next('.nested-gridfield').hide(); $(this).closest('tr').next('.nested-gridfield').hide();
$(this).removeClass('font-icon-down-dir'); $(this).removeClass('font-icon-down-dir');
$(this).addClass('font-icon-right-dir'); $(this).addClass('font-icon-right-dir');