Skip to content
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

Compatibility issue with repeatable fields #73

Open
ctlcltd opened this issue Jul 22, 2023 · 4 comments
Open

Compatibility issue with repeatable fields #73

ctlcltd opened this issue Jul 22, 2023 · 4 comments

Comments

@ctlcltd
Copy link

ctlcltd commented Jul 22, 2023

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();
  });
}

👋

@Ipstenu
Copy link

Ipstenu commented Oct 2, 2023

@ctlcltd How are you calling this to make it work?

@ctlcltd
Copy link
Author

ctlcltd commented Oct 3, 2023 via email

@Ipstenu
Copy link

Ipstenu commented Oct 3, 2023

@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.

@ctlcltd
Copy link
Author

ctlcltd commented Oct 3, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants