Skip to content

Commit

Permalink
Fix Tiny bug in Html field when using dependsOn keystonejs#3551
Browse files Browse the repository at this point in the history
  • Loading branch information
iamfozzy committed Oct 2, 2016
1 parent e92832e commit 4b7e7bb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
6 changes: 0 additions & 6 deletions admin/client/App/screens/Item/components/EditForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,6 @@ var EditForm = React.createClass({
if (typeof Fields[field.type] !== 'function') {
return React.createElement(InvalidFieldType, { type: field.type, path: field.path, key: field.path });
}
if (props.dependsOn) {
props.currentDependencies = {};
Object.keys(props.dependsOn).forEach(dep => {
props.currentDependencies[dep] = this.state.values[dep];
});
}
props.key = field.path;
if (index === 0 && this.state.focusFirstField) {
props.autoFocus = true;
Expand Down
35 changes: 21 additions & 14 deletions fields/types/html/HtmlField.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Field from '../Field';
import React from 'react';
import tinymce from 'tinymce';
import { FormInput } from 'elemental';
import evalDependsOn from '../../utils/evalDependsOn';

/**
* TODO:
Expand Down Expand Up @@ -35,6 +36,7 @@ module.exports = Field.create({
return {
id: getId(),
isFocused: false,
wysiwygActive: false,
};
},

Expand All @@ -53,29 +55,34 @@ module.exports = Field.create({

this._currentValue = this.props.value;
tinymce.init(opts);
this.setState({ wysiwygActive: true });
},

removeWysiwyg (state) {
removeTinyMCEInstance(tinymce.get(state.id));
this.setState({ wysiwygActive: false });
},

componentDidUpdate (prevProps, prevState) {
if (prevState.isCollapsed && !this.state.isCollapsed) {
this.initWysiwyg();
}

if (!_.isEqual(this.props.currentDependencies, prevProps.currentDependencies)) {
if (_.isEqual(prevProps.dependsOn, prevProps.currentDependencies)) {
var instance = tinymce.get(prevState.id);
if (instance) {
removeTinyMCEInstance(instance);
}
}

if (_.isEqual(this.props.dependsOn, this.props.currentDependencies)) {
this.initWysiwyg();
}
}

if (this.props.wysiwyg) {
if (evalDependsOn(this.props.dependsOn, this.props.values) ) {
if (!this.state.wysiwygActive) {
this.initWysiwyg();
}
} else if (this.state.wysiwygActive) {
this.removeWysiwyg(prevState);
}
}
},

componentDidMount () {
this.initWysiwyg();
if (evalDependsOn(this.props.dependsOn, this.props.values)) {
this.initWysiwyg();
}
},

componentWillReceiveProps (nextProps) {
Expand Down

0 comments on commit 4b7e7bb

Please sign in to comment.