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

FR: Add an event when saving in a Craft.ElementEditor hud #2689

joshangell opened this issue Apr 5, 2018 · 2 comments


None yet
2 participants
Copy link

commented Apr 5, 2018


When saving in the Craft.ElementEditor hud it would be helpful for other JavaScript to be able know that that has happened.

For my current use-case I am building some more live preview tools that work inside a field type and whilst I can do similar things to the core Craft.LivePreview class in terms of regularly checking if field content has changed, I can’t do anything about updating my previews when someone clicks save in an element editor hud.

I have created a PR to illustrate the sort of behaviour I am after: #2688

Steps to reproduce

  1. Navigate to an entry with an element field attached
  2. Select an element and save it on the field
  3. Double-click the element once its on the field to edit, then press save

Additional info

  • Craft version: 2.6.3014
  • PHP version: 7.1.x

This comment has been minimized.

Copy link

commented Apr 8, 2018

Solved this by adding support for class-level event listeners to Garnish.

So now you can do this in your code:

Garnish.on(Craft.BaseElementEditor, 'saveElement', callback);

// later, if you need to disable the event handler, 'saveElement', callback);

The callback method will get called any time any Craft.BaseElementEditor fires a saveElement event. So you don’t need to have a handle on the element editor instance ahead of time.

Make sure callback is the exact same function reference if you do in fact need to call at some point.

As an example, I also updated the Craft.LivePreview class to use this method, rather than Craft.BaseElementEditor being the one to notify Live Preview when an element is saved: 6c52ddb


This comment has been minimized.

Copy link
Contributor Author

commented Apr 9, 2018

Ah this is brilliant, works a treat - thank you Brandon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.