diff --git a/frontend/src/pages/org/settings/settings.ts b/frontend/src/pages/org/settings/settings.ts index 76a6e5888..dba3d5cca 100644 --- a/frontend/src/pages/org/settings/settings.ts +++ b/frontend/src/pages/org/settings/settings.ts @@ -239,10 +239,7 @@ export class OrgSettings extends TailwindElement { : this.org.slug }`, )} - @sl-input=${(e: InputEvent) => { - const input = e.target as SlInput; - this.slugValue = input.value; - }} + @sl-input=${this.handleSlugInput} > `, msg( @@ -275,6 +272,19 @@ export class OrgSettings extends TailwindElement { `; } + private handleSlugInput(e: InputEvent) { + const input = e.target as SlInput; + // Ideally this would match against the full character map that slugify uses + // but this'll do for most use cases + const end = input.value.match(/[\s*_+~.,()'"!\-:@]$/g) ? "-" : ""; + input.value = slugifyStrict(input.value) + end; + this.slugValue = slugifyStrict(input.value); + + input.setCustomValidity( + this.slugValue.length < 2 ? msg("URL Identifier too short") : "", + ); + } + private renderMembers() { if (!this.org?.users) return;