Normalize alias a little, display initial sigil

turns all whitespace into underscores, shows leading
sigil if the alias is non-empty, so the user doesn't get
confused about whether they have to input a # or not.

Change-Id: Ic81e69cc3f0074d63a67b976c9bda32f8de025de
This commit is contained in:
Timo Paulssen 2020-04-17 00:09:56 +02:00
parent c1c32e3268
commit 24abcd4e4a

View File

@ -76,6 +76,8 @@ const validateAlias = fieldval => {
}
const removeLeadingWhitespace = fieldVal => fieldVal === undefined ? undefined : fieldVal.trimStart();
const replaceAllWhitespace = fieldVal => fieldVal === undefined ? undefined : fieldVal.replace(/\s/, "_");
const removeLeadingSigil = fieldVal => fieldVal === undefined ? undefined : fieldVal.startsWith("#") ? fieldVal.substr(1) : fieldVal;
const validateHasAliasIfPublic = formdata => {
let errors = {};
@ -94,7 +96,8 @@ export const RoomCreate = props => (
parse={removeLeadingWhitespace}
validate={validateDisplayName}/>
<TextInput source="alias"
parse={removeLeadingWhitespace}
parse={fv => replaceAllWhitespace(removeLeadingSigil(fv)) }
format={fv => fv === "" ? "" : "#" + fv}
validate={validateAlias}/>
<BooleanInput source="public"
label="synapseadmin.rooms.make_public"/>