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

FIX Changing the value of a TinyMCE field will correctly trigger a change in the React component #682

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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