Skip to content

Compatibility issue with repeatable fields #73

@ctlcltd

Description

@ctlcltd

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

👋

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions