Skip to content

Commit

Permalink
Merge pull request #682 from creative-commoners/pulls/4.3/re-tinymce-…
Browse files Browse the repository at this point in the history
…act-events

FIX Changing the value of a TinyMCE field will correctly trigger a change in the React component
  • Loading branch information
robbieaverill authored Oct 15, 2018
2 parents 7a8819c + 4702a22 commit f013e82
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion client/src/components/HtmlEditorField/HtmlEditorField.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ class HtmlEditorField extends TextField {
const unmountEvent = $.Event('EntwineElementsRemoved');
const editorElement = document.getElementById(this.getInputProps().id);
// Tell tinyMCE to persist changes into the text field
$(editorElement).entwine('ss').getEditor().save();
const editor = $(editorElement).entwine('ss').getEditor();
if (editor) {
editor.save();
}
unmountEvent.targets = [editorElement];
// Ensure that redux knows of the latest changes before the editor is destroyed.
// This is pretty awful because TinyMCE triggers jQuery events which aren't picked up
Expand Down
3 changes: 3 additions & 0 deletions client/src/components/TextField/TextField.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class TextField extends Component {
*/
handleChange(event) {
if (typeof this.props.onChange === 'function') {
if (!event.target) {
return;
}
this.props.onChange(event, { id: this.props.id, value: event.target.value });
}
}
Expand Down
1 change: 1 addition & 0 deletions client/src/legacy/HtmlEditorField.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ ss.editorWrappers.tinyMCE = (function() {
// Update change detection
if(!options.silent) {
jQuery(instance.getElement()).trigger("change");
instance.getElement().dispatchEvent(new Event('input', { bubbles: true }));
}
},

Expand Down

0 comments on commit f013e82

Please sign in to comment.