mirror of https://github.com/vector-im/riot-web
Merge pull request #4153 from matrix-org/t3chguy/alias_invalid_valid
don't show "This alias is available to use" if the alias is invalidpull/21833/head
commit
3ba86ee655
|
@ -92,6 +92,7 @@ export default class RoomAliasField extends React.PureComponent {
|
||||||
invalid: () => _t("Please provide a room alias"),
|
invalid: () => _t("Please provide a room alias"),
|
||||||
}, {
|
}, {
|
||||||
key: "taken",
|
key: "taken",
|
||||||
|
final: true,
|
||||||
test: async ({value}) => {
|
test: async ({value}) => {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -28,9 +28,11 @@ import classNames from 'classnames';
|
||||||
* An array of rules describing how to check to input value. Each rule in an object
|
* An array of rules describing how to check to input value. Each rule in an object
|
||||||
* and may have the following properties:
|
* and may have the following properties:
|
||||||
* - `key`: A unique ID for the rule. Required.
|
* - `key`: A unique ID for the rule. Required.
|
||||||
|
* - `skip`: A function used to determine whether the rule should even be evaluated.
|
||||||
* - `test`: A function used to determine the rule's current validity. Required.
|
* - `test`: A function used to determine the rule's current validity. Required.
|
||||||
* - `valid`: Function returning text to show when the rule is valid. Only shown if set.
|
* - `valid`: Function returning text to show when the rule is valid. Only shown if set.
|
||||||
* - `invalid`: Function returning text to show when the rule is invalid. Only shown if set.
|
* - `invalid`: Function returning text to show when the rule is invalid. Only shown if set.
|
||||||
|
* - `final`: A Boolean if true states that this rule will only be considered if all rules before it returned valid.
|
||||||
* @returns {Function}
|
* @returns {Function}
|
||||||
* A validation function that takes in the current input value and returns
|
* A validation function that takes in the current input value and returns
|
||||||
* the overall validity and a feedback UI that can be rendered for more detail.
|
* the overall validity and a feedback UI that can be rendered for more detail.
|
||||||
|
@ -51,9 +53,20 @@ export default function withValidation({ description, rules }) {
|
||||||
if (!rule.key || !rule.test) {
|
if (!rule.key || !rule.test) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!valid && rule.final) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = { value, allowEmpty };
|
||||||
|
|
||||||
|
if (rule.skip && rule.skip.call(this, data)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// We're setting `this` to whichever component holds the validation
|
// We're setting `this` to whichever component holds the validation
|
||||||
// function. That allows rules to access the state of the component.
|
// 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;
|
valid = valid && ruleValid;
|
||||||
if (ruleValid && rule.valid) {
|
if (ruleValid && rule.valid) {
|
||||||
// If the rule's result is valid and has text to show for
|
// If the rule's result is valid and has text to show for
|
||||||
|
|
Loading…
Reference in New Issue