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

[Feature Request] Add onChange callback #46

Closed
carylgaskell opened this issue Dec 13, 2018 · 3 comments
Closed

[Feature Request] Add onChange callback #46

carylgaskell opened this issue Dec 13, 2018 · 3 comments

Comments

@carylgaskell
Copy link

I'm using the builder along with some other text fields as a "form" but in order to determine if the form is dirty I'd need to know if an update to the builder occurred. It would be great to expose an onChangeCallback prop. I'm sure others would want to use it to save changes automatically without clicking a button.

onChange = (html, design) => {
    this.props.setSomeFieldValue(html);
    this.props.setMyAwesomeFormDirty();
}

Thanks and great work!

@carylgaskell
Copy link
Author

Jk. I figured it out. attaching the event listener in the onLoad like so

  onLoad = () => {
    const { design } = this.props.values;
    if (design) {
      window.unlayer.loadDesign(design);
    }
    window.unlayer.addEventListener('design:updated', (data) => {
      this.setState({ designUpdated: true });
    });
  }

@generalleger
Copy link

@carylgaskell does your event listener trigger on each keystroke? As far as I can tell. A user can click into the editor and start typing and the 'design:updated' listener does not trigger. If the user clicks out of the iframe, it triggers.

There used to be a bunch of different listeners, and one of them (not sure which) would trigger the call back on each keystroke if someone were typing into the iframe. It was convenient, because, like you, i needed to know when the form was 'dirty'.

In lieu of that, I added an event listener to tell me when the user clicks into the iframe, which assumes that they will start typing once they click, which is not entirely ideal.

var listener = window.addEventListener('blur', () => {
      if (document.activeElement.nodeName === "IFRAME") {
          //do something here
      }
      window.removeEventListener('blur', listener);
});

@ajiths10
Copy link

ajiths10 commented May 4, 2023

Here is a sample, with on change and load existing design.
https://github.com/ajiths10/EmailEditor-ReactApp/blob/main/src/component/AdvancedEditor.tsx

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

3 participants