From 86a1327259da5c1ed573bd4a3fd29c3acb5ef018 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sat, 29 Feb 2020 00:31:56 +0000 Subject: [PATCH] don't show "This alias is available to use" if an alias is not provided Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/views/elements/RoomAliasField.js | 1 + src/components/views/elements/Validation.js | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/components/views/elements/RoomAliasField.js b/src/components/views/elements/RoomAliasField.js index 007bd07a47..0139a9596b 100644 --- a/src/components/views/elements/RoomAliasField.js +++ b/src/components/views/elements/RoomAliasField.js @@ -92,6 +92,7 @@ export default class RoomAliasField extends React.PureComponent { invalid: () => _t("Please provide a room alias"), }, { key: "taken", + skip: ({value}) => !value, test: async ({value}) => { if (!value) { return true; diff --git a/src/components/views/elements/Validation.js b/src/components/views/elements/Validation.js index 31363b87c8..3454ab3aec 100644 --- a/src/components/views/elements/Validation.js +++ b/src/components/views/elements/Validation.js @@ -51,9 +51,16 @@ export default function withValidation({ description, rules }) { if (!rule.key || !rule.test) { continue; } + + const data = { value, allowEmpty }; + + if (rule.skip && rule.skip.call(this, data)) { + continue; + } + // We're setting `this` to whichever component holds the validation // function. That allows rules to access the state of the component. - const ruleValid = await rule.test.call(this, { value, allowEmpty }); + const ruleValid = await rule.test.call(this, data); valid = valid && ruleValid; if (ruleValid && rule.valid) { // If the rule's result is valid and has text to show for