Skip to content

Commit 821ab6c

Browse files
committed
switch to controlled inputs and require eventType !== ''
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
1 parent 828e9d5 commit 821ab6c

1 file changed

Lines changed: 29 additions & 12 deletions

File tree

‎src/components/views/dialogs/DevtoolsDialog.js‎

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,14 @@ class SendCustomEvent extends React.Component {
2929
super(props, context);
3030
this._send = this._send.bind(this);
3131
this.onBack = this.onBack.bind(this);
32-
}
32+
this._onChange = this._onChange.bind(this);
3333

34-
state = {
35-
message: null,
36-
};
34+
this.state = {
35+
message: null,
36+
input_eventType: '',
37+
input_evContent: '{\n\n}',
38+
};
39+
}
3740

3841
onBack() {
3942
if (this.state.message) {
@@ -51,13 +54,18 @@ class SendCustomEvent extends React.Component {
5154
}
5255

5356
send(content) {
54-
return MatrixClientPeg.get().sendEvent(this.props.roomId, this.refs.eventType.value, content);
57+
return MatrixClientPeg.get().sendEvent(this.props.roomId, this.state.input_eventType, content);
5558
}
5659

5760
async _send() {
61+
if (this.state.input_eventType === '') {
62+
this.setState({ message: _t('You must specify an event type!') });
63+
return;
64+
}
65+
5866
let message;
5967
try {
60-
const content = JSON.parse(this.refs.evContent.value);
68+
const content = JSON.parse(this.state.input_evContent);
6169
await this.send(content);
6270
message = _t('Event sent!');
6371
} catch (e) {
@@ -67,7 +75,11 @@ class SendCustomEvent extends React.Component {
6775
}
6876

6977
_additionalFields() {
70-
return <div></div>;
78+
return <div/>;
79+
}
80+
81+
_onChange(e) {
82+
this.setState({[`input_${e.target.id}`]: e.target.value});
7183
}
7284

7385
render() {
@@ -87,14 +99,14 @@ class SendCustomEvent extends React.Component {
8799
<label htmlFor="eventType"> { _t('Event Type') } </label>
88100
</div>
89101
<div>
90-
<input id="eventType" ref="eventType" className="mx_TextInputDialog_input" size="64" />
102+
<input id="eventType" onChange={this._onChange} value={this.state.input_eventType} className="mx_TextInputDialog_input" size="64" />
91103
</div>
92104

93105
<div className="mx_TextInputDialog_label">
94106
<label htmlFor="evContent"> { _t('Event Content') } </label>
95107
</div>
96108
<div>
97-
<textarea id="evContent" ref="evContent" className="mx_TextInputDialog_input" defaultValue={"{\n\n}"} cols="63" rows="5" />
109+
<textarea id="evContent" onChange={this._onChange} value={this.state.input_evContent} className="mx_TextInputDialog_input" cols="63" rows="5" />
98110
</div>
99111
</div>
100112
{this._buttons()}
@@ -103,9 +115,14 @@ class SendCustomEvent extends React.Component {
103115
}
104116

105117
class SendCustomStateEvent extends SendCustomEvent {
118+
constructor(props, context) {
119+
super(props, context);
120+
this.state['input_stateKey'] = '';
121+
}
122+
106123
send(content) {
107-
return MatrixClientPeg.get().sendStateEvent(this.props.roomId, this.refs.eventType.value, content,
108-
this.refs.stateKey.value);
124+
const cli = MatrixClientPeg.get();
125+
return cli.sendStateEvent(this.props.roomId, this.state.input_eventType, content, this.state.input_stateKey);
109126
}
110127

111128
_additionalFields() {
@@ -114,7 +131,7 @@ class SendCustomStateEvent extends SendCustomEvent {
114131
<label htmlFor="stateKey"> { _t('State Key') } </label>
115132
</div>
116133
<div>
117-
<input id="stateKey" ref="stateKey" className="mx_TextInputDialog_input" size="64" />
134+
<input id="stateKey" onChange={this._onChange} value={this.state.input_stateKey} className="mx_TextInputDialog_input" size="64" />
118135
</div>
119136
</div>;
120137
}

0 commit comments

Comments
 (0)