From 24abcd4e4a4c111eb33fbb2bc7a234dc74e5b8c2 Mon Sep 17 00:00:00 2001 From: Timo Paulssen Date: Fri, 17 Apr 2020 00:09:56 +0200 Subject: [PATCH] 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 --- src/components/rooms.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/rooms.js b/src/components/rooms.js index 57c113e..1e84958 100644 --- a/src/components/rooms.js +++ b/src/components/rooms.js @@ -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}/> replaceAllWhitespace(removeLeadingSigil(fv)) } + format={fv => fv === "" ? "" : "#" + fv} validate={validateAlias}/>