cmb2-attached-posts
cmb2-attached-posts copied to clipboard
Compatibility issue with repeatable fields
cmb2-attached-posts won't works with CMB2 repeatable fields.
Fields are cloned but not resetted, and there is an error with assigning draggable/droppable jquery-ui to cloned elements.
I solved this way:
if (window.CMBAP) {
jQuery('.cmb-repeatable-group').on('cmb2_add_row', function(event, newRow) {
var app = window.CMBAP;
// draggables
app.cache();
app.makeDraggable();
app.makeDroppable();
// reset
jQuery(newRow).find('.attached-posts-wrap').each(function() {
var $wrap = jQuery(this);
$wrap.find('.attached-posts-ids').val('');
$wrap.find('.retrieved li').each(function() {
jQuery(this).removeClass('added');
});
$wrap.find('.attached li').each(function() {
jQuery(this).remove();
});
app.resetAttachedListItems($wrap);
app.updateReadOnly($wrap);
app.updateRemaining($wrap);
});
app.cache();
});
}
:wave:
@ctlcltd How are you calling this to make it work?
the call is implicit on line 2 of the snippet, on the cmb2_add_row
hook
event
Il mar 3 ott 2023, 01:53 Ipstenu (Mika Epstein) @.***> ha scritto:
@ctlcltd https://github.com/ctlcltd How are you calling this to make it work?
— Reply to this email directly, view it on GitHub https://github.com/CMB2/cmb2-attached-posts/issues/73#issuecomment-1743934662, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABSBHJYW72GD2YPVZUDKMLX5NHXDAVCNFSM6AAAAAA2TXQMPKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONBTHEZTINRWGI . You are receiving this because you were mentioned.Message ID: @.***>
@ctlcltd I mean, where in the PHP. I can make this a random named JS file but I gotta enqueue it. There are a bunch of different ways to do that, and I was curious what yours was.
The snippet is a buffer fix, to apply it I used a js file hooked to the
admin_enqueue_scripts
hook from a php file of the theme. A definitive
solution to be compatible with repeatable would be to modify the
js/attached-posts.js script, something similar to the snippet but
incorporated into the original source.