You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-07-24 06:02:08 +03:00
add validation when clicking Ok in dialog
This commit is contained in:
@ -72,7 +72,31 @@ export default createReactClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
onOk: async function() {
|
onOk: async function() {
|
||||||
|
const activeElement = document.activeElement;
|
||||||
|
if (activeElement) {
|
||||||
|
activeElement.blur();
|
||||||
|
}
|
||||||
|
await this._nameFieldRef.validate({allowEmpty: false});
|
||||||
|
if (this._aliasFieldRef) {
|
||||||
|
await this._aliasFieldRef.validate({allowEmpty: false});
|
||||||
|
}
|
||||||
|
// Validation and state updates are async, so we need to wait for them to complete
|
||||||
|
// first. Queue a `setState` callback and wait for it to resolve.
|
||||||
|
await new Promise(resolve => this.setState({}, resolve));
|
||||||
|
if (this.state.nameIsValid && (!this._aliasFieldRef || this._aliasFieldRef.isValid)) {
|
||||||
this.props.onFinished(true, this._roomCreateOptions());
|
this.props.onFinished(true, this._roomCreateOptions());
|
||||||
|
} else {
|
||||||
|
let field;
|
||||||
|
if (!this.state.nameIsValid) {
|
||||||
|
field = this._nameFieldRef;
|
||||||
|
} else if (this._aliasFieldRef && !this._aliasFieldRef.isValid) {
|
||||||
|
field = this._aliasFieldRef;
|
||||||
|
}
|
||||||
|
if (field) {
|
||||||
|
field.focus();
|
||||||
|
field.validate({ allowEmpty: false, focused: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onCancel: function() {
|
onCancel: function() {
|
||||||
|
Reference in New Issue
Block a user