Reset JSONEditor after it loosed focus

This commit is contained in:
Lukas Martinelli 2016-12-31 14:37:40 +01:00
parent c3a634b216
commit e00cdde3af

View file

@ -56,6 +56,13 @@ class JSONEditor extends React.Component {
} }
} }
resetValue() {
console.log('reset')
this.setState({
code: JSON.stringify(this.props.layer, null, 2)
})
}
render() { render() {
const codeMirrorOptions = { const codeMirrorOptions = {
mode: {name: "javascript", json: true}, mode: {name: "javascript", json: true},
@ -69,6 +76,7 @@ class JSONEditor extends React.Component {
return <CodeMirror return <CodeMirror
value={this.state.code} value={this.state.code}
onChange={this.onCodeUpdate.bind(this)} onChange={this.onCodeUpdate.bind(this)}
onFocusChange={focused => focused ? true : this.resetValue()}
options={codeMirrorOptions} options={codeMirrorOptions}
/> />
} }