From 821ab6c13eb69d0af4372395d218b8f0928fa935 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 18 Sep 2017 11:06:46 +0100 Subject: [PATCH 1/4] switch to controlled inputs and require eventType !== '' Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .../views/dialogs/DevtoolsDialog.js | 41 +++++++++++++------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/src/components/views/dialogs/DevtoolsDialog.js b/src/components/views/dialogs/DevtoolsDialog.js index a7ac9fb1c..22fd712db 100644 --- a/src/components/views/dialogs/DevtoolsDialog.js +++ b/src/components/views/dialogs/DevtoolsDialog.js @@ -29,11 +29,14 @@ class SendCustomEvent extends React.Component { super(props, context); this._send = this._send.bind(this); this.onBack = this.onBack.bind(this); - } + this._onChange = this._onChange.bind(this); - state = { - message: null, - }; + this.state = { + message: null, + input_eventType: '', + input_evContent: '{\n\n}', + }; + } onBack() { if (this.state.message) { @@ -51,13 +54,18 @@ class SendCustomEvent extends React.Component { } send(content) { - return MatrixClientPeg.get().sendEvent(this.props.roomId, this.refs.eventType.value, content); + return MatrixClientPeg.get().sendEvent(this.props.roomId, this.state.input_eventType, content); } async _send() { + if (this.state.input_eventType === '') { + this.setState({ message: _t('You must specify an event type!') }); + return; + } + let message; try { - const content = JSON.parse(this.refs.evContent.value); + const content = JSON.parse(this.state.input_evContent); await this.send(content); message = _t('Event sent!'); } catch (e) { @@ -67,7 +75,11 @@ class SendCustomEvent extends React.Component { } _additionalFields() { - return
; + return
; + } + + _onChange(e) { + this.setState({[`input_${e.target.id}`]: e.target.value}); } render() { @@ -87,14 +99,14 @@ class SendCustomEvent extends React.Component {
- +
-