adds validation for fields.

* renames RoomTooltip to be a generic Tooltip (which it is)
 * hooks it into Field to show validation results
 * adds onValidate to Field to let Field instances call an arbitrary validation function

Rebased from @ara4n's https://github.com/matrix-org/matrix-react-sdk/pull/2550
by @jryans. Subsequent commits revise and adapt this work.
This commit is contained in:
Matthew Hodgson 2019-02-01 00:36:19 +01:00 committed by J. Ryan Stinnett
parent a5c1d6733f
commit 40f16fa310
15 changed files with 154 additions and 47 deletions

View file

@ -90,6 +90,15 @@ export default class ServerConfig extends React.PureComponent {
this.setState({ hsUrl });
}
onHomeserverValidate = (value) => {
try {
new URL(value);
return { valid: true, feedback: <div>Valid URL!</div> };
} catch (_) {
return { valid: false, feedback: <div>Invalid URL!</div>};
}
}
onIdentityServerBlur = (ev) => {
this._isTimeoutId = this._waitThenInvoke(this._isTimeoutId, () => {
this.props.onServerConfigChange({
@ -134,6 +143,7 @@ export default class ServerConfig extends React.PureComponent {
value={this.state.hsUrl}
onBlur={this.onHomeserverBlur}
onChange={this.onHomeserverChange}
onValidate={this.onHomeserverValidate}
/>
<Field id="mx_ServerConfig_isUrl"
label={_t("Identity Server URL")}