Hube2 / acf-medium-editor

Configurable Medium Editor WYSIWYG Field for ACF5 Pro
77 stars 10 forks source link

not always updated #2

Closed Hube2 closed 7 years ago

Hube2 commented 7 years ago

The content in the text field submitted when updating a post does not always get updated before the post is submitted. No idea what's causing this yet.

Hube2 commented 7 years ago

It has something to do with this https://github.com/yabwe/medium-editor/issues/942

If I use a standard button after using a custom MediumButton then the field gets updated. But if I use the custom button last then that update is not recorded.

I asked a question here https://github.com/arcs-/MediumButton/issues/14, we'll see what happens. I can't see where I can apply the changes suggested in the medium editor issue to the medium button code.

Hube2 commented 7 years ago

I've hacked something together for this, for anyone that happens. For anyone that happens upon this in the future looking for to solve a similar problem. At least I think this solves the problem, need to do some more testing to be sure.

// instantiate MediumEditor
// this is from the docs there
var editor = new MediumEditor(selector, object);
// get the id value of the editor just created
var editorId = editor.elements[0].id;
// get this element in a form that we can pass back to medium editor as the target
var target = document.getElementById(editorId);
// get the textarea that for this editor
// in my case there is only one because each one has a unique ID
var targetObj = document.getElementById('my-unique-id');
// attach action DOMSubtreeModified to the editor
$('#'+editorId).bind('DOMSubtreeModified', function(e) {
    // force medium editor to update/refresh
    editor.events.updateInput($target, $targetObj);
});