fix SafeTextarea clear()
This commit is contained in:
@@ -283,7 +283,7 @@ export class SafeTextarea extends Component {
|
|||||||
};
|
};
|
||||||
this.on_change_bound = this.on_change.bind(this);
|
this.on_change_bound = this.on_change.bind(this);
|
||||||
this.on_keydown_bound = this.on_keydown.bind(this);
|
this.on_keydown_bound = this.on_keydown.bind(this);
|
||||||
this.clear = this.clear.bind(this);
|
this.clear_and_then = this.clear_and_then.bind(this);
|
||||||
this.area_ref = React.createRef();
|
this.area_ref = React.createRef();
|
||||||
this.change_callback = props.on_change || (() => {});
|
this.change_callback = props.on_change || (() => {});
|
||||||
this.submit_callback = props.on_submit || (() => {});
|
this.submit_callback = props.on_submit || (() => {});
|
||||||
@@ -311,6 +311,7 @@ export class SafeTextarea extends Component {
|
|||||||
});
|
});
|
||||||
this.change_callback(event.target.value);
|
this.change_callback(event.target.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
on_keydown(event) {
|
on_keydown(event) {
|
||||||
if (event.key === 'Enter' && event.ctrlKey && !event.altKey) {
|
if (event.key === 'Enter' && event.ctrlKey && !event.altKey) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@@ -318,20 +319,26 @@ export class SafeTextarea extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clear() {
|
clear_and_then(callback = null) {
|
||||||
this.setState({
|
this.setState(
|
||||||
text: '',
|
{
|
||||||
});
|
text: '',
|
||||||
|
},
|
||||||
|
callback,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
set(text) {
|
set(text) {
|
||||||
this.change_callback(text);
|
this.change_callback(text);
|
||||||
this.setState({
|
this.setState({
|
||||||
text: text,
|
text: text,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
get() {
|
get() {
|
||||||
return this.state.text;
|
return this.state.text;
|
||||||
}
|
}
|
||||||
|
|
||||||
focus() {
|
focus() {
|
||||||
this.area_ref.current.focus();
|
this.area_ref.current.focus();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -425,13 +425,16 @@ export class ReplyForm extends Component {
|
|||||||
save_attentions();
|
save_attentions();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setState({
|
this.setState(
|
||||||
loading_status: 'done',
|
{
|
||||||
text: '',
|
loading_status: 'done',
|
||||||
preview: false,
|
text: '',
|
||||||
});
|
preview: false,
|
||||||
this.area_ref.current.clear();
|
},
|
||||||
this.props.on_complete();
|
() => {
|
||||||
|
this.area_ref.current.clear_and_then(this.props.on_complete);
|
||||||
|
},
|
||||||
|
);
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
@@ -602,15 +605,18 @@ export class PostForm extends Component {
|
|||||||
throw new Error(json.msg);
|
throw new Error(json.msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setState({
|
|
||||||
loading_status: 'done',
|
|
||||||
text: '',
|
|
||||||
preview: false,
|
|
||||||
});
|
|
||||||
this.area_ref.current.clear();
|
|
||||||
this.props.on_complete();
|
|
||||||
window.CW_BACKUP = '';
|
window.CW_BACKUP = '';
|
||||||
window.POLL_BACKUP = null;
|
window.POLL_BACKUP = null;
|
||||||
|
this.setState(
|
||||||
|
{
|
||||||
|
loading_status: 'done',
|
||||||
|
text: '',
|
||||||
|
preview: false,
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
this.area_ref.current.clear_and_then(this.props.on_complete);
|
||||||
|
},
|
||||||
|
);
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
|||||||
Reference in New Issue
Block a user