From 3e0278d41a3893b1540b8d49e5b3a01e52930c85 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 20 Sep 2019 17:46:47 +0200 Subject: [PATCH] add validation when clicking Ok in dialog --- .../views/dialogs/CreateRoomDialog.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/components/views/dialogs/CreateRoomDialog.js b/src/components/views/dialogs/CreateRoomDialog.js index 501e6b6f80..e3070cfef3 100644 --- a/src/components/views/dialogs/CreateRoomDialog.js +++ b/src/components/views/dialogs/CreateRoomDialog.js @@ -72,7 +72,31 @@ export default createReactClass({ }, 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()); + } 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() {