1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-11-07 10:46:24 +03:00

refactor to add Validation::final

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski
2020-02-29 01:00:57 +00:00
parent 3e85f65d9e
commit 8aaab0a3ba
2 changed files with 11 additions and 9 deletions

View File

@@ -38,13 +38,6 @@ export default class RoomAliasField extends React.PureComponent {
return `#${localpart}:${this.props.domain}`;
}
_isValid(value) {
const fullAlias = this._asFullAlias(value);
// XXX: FIXME https://github.com/matrix-org/matrix-doc/issues/668
return !value.includes("#") && !value.includes(":") && !value.includes(",") &&
encodeURI(fullAlias) === fullAlias;
}
render() {
const Field = sdk.getComponent('views.elements.Field');
const poundSign = (<span>#</span>);
@@ -87,7 +80,10 @@ export default class RoomAliasField extends React.PureComponent {
if (!value) {
return true;
}
return this._isValid(value);
const fullAlias = this._asFullAlias(value);
// XXX: FIXME https://github.com/matrix-org/matrix-doc/issues/668
return !value.includes("#") && !value.includes(":") && !value.includes(",") &&
encodeURI(fullAlias) === fullAlias;
},
invalid: () => _t("Some characters not allowed"),
}, {
@@ -96,7 +92,7 @@ export default class RoomAliasField extends React.PureComponent {
invalid: () => _t("Please provide a room alias"),
}, {
key: "taken",
skip: ({value}) => !value || !this._isValid(value),
final: true,
test: async ({value}) => {
if (!value) {
return true;