Jump to content

A snippet to add additional support for detecting "hidden" changes in RPB blocks


FireWire
 Share

Recommended Posts

@bernhard I was working on some blocks in RPB and noticed that there were some edge cases where changes weren't being detected by RPB. I ran into this with the trash icon on RepeaterMatrix items. Clicking it checks a hidden checkbox programmatically and doesn't emit a change event, so it's pretty much invisible to everything else that isn't RepeaterMatrix code.

I added this mutation observer to InputfieldRockPageBuilder.js to watch for elements that have had the 'InputfieldStateChanged' class added.

// trigger changed event when InputfieldStateChanged is added to elements
$(document).on('ready', function () {
  const rpbItemsObserver = new MutationObserver(mutations => {
    mutations.forEach(mutation => {
      if (mutation.target.classList.contains('InputfieldStateChanged')) {
        RockPageBuilder.changed(mutation);
      }
    });
  });

  $('.rpb-items').each(function (_, rpbItem) {
    rpbItemsObserver.observe(rpbItem, {
      childList: true,
      subtree: true,
      attributes: true,
      attributeFilter: ['class']
    });
  });
});

In my testing this took care of some edge cases where changes aren't visible to RPB. Could be helpful for handling other sneaky inputs as well πŸ‘

  • Like 2
Link to comment
Share on other sites

@bernhard So glad it helped out! Nice to know that it addressed another challenge.

Your modules are so great to work with and really improve the developer and user experiences.

The less time you spend fixing things is more time you have for building awesome stuff, so I'm happy to help  πŸ˜Ž

  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
Γ—
Γ—
  • Create New...