web: live-convert to slug in fields where only slugs are allowed
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
		| @ -9,6 +9,7 @@ import PFForm from "@patternfly/patternfly/components/Form/form.css"; | |||||||
| import PFFormControl from "@patternfly/patternfly/components/FormControl/form-control.css"; | import PFFormControl from "@patternfly/patternfly/components/FormControl/form-control.css"; | ||||||
| import PFBase from "@patternfly/patternfly/patternfly-base.css"; | import PFBase from "@patternfly/patternfly/patternfly-base.css"; | ||||||
|  |  | ||||||
|  | import { convertToSlug } from "../../utils"; | ||||||
| import { FormGroup } from "./FormGroup"; | import { FormGroup } from "./FormGroup"; | ||||||
|  |  | ||||||
| @customElement("ak-form-element-horizontal") | @customElement("ak-form-element-horizontal") | ||||||
| @ -48,6 +49,9 @@ export class HorizontalFormElement extends LitElement { | |||||||
|     @property({ attribute: false }) |     @property({ attribute: false }) | ||||||
|     errorMessages: string[] = []; |     errorMessages: string[] = []; | ||||||
|  |  | ||||||
|  |     @property({ type: Boolean }) | ||||||
|  |     slugMode = false; | ||||||
|  |  | ||||||
|     _invalid = false; |     _invalid = false; | ||||||
|  |  | ||||||
|     @property({ type: Boolean }) |     @property({ type: Boolean }) | ||||||
| @ -70,6 +74,13 @@ export class HorizontalFormElement extends LitElement { | |||||||
|         this.querySelectorAll<HTMLInputElement>("input[autofocus]").forEach((input) => { |         this.querySelectorAll<HTMLInputElement>("input[autofocus]").forEach((input) => { | ||||||
|             input.focus(); |             input.focus(); | ||||||
|         }); |         }); | ||||||
|  |         if (this.name === "slug" || this.slugMode) { | ||||||
|  |             this.querySelectorAll<HTMLInputElement>("input[type='text']").forEach((input) => { | ||||||
|  |                 input.addEventListener("keyup", () => { | ||||||
|  |                     input.value = convertToSlug(input.value); | ||||||
|  |                 }); | ||||||
|  |             }); | ||||||
|  |         } | ||||||
|         this.querySelectorAll("*").forEach((input) => { |         this.querySelectorAll("*").forEach((input) => { | ||||||
|             switch (input.tagName.toLowerCase()) { |             switch (input.tagName.toLowerCase()) { | ||||||
|                 case "input": |                 case "input": | ||||||
|  | |||||||
| @ -1,5 +1,3 @@ | |||||||
| import { UserVerificationEnum } from "@goauthentik/api/dist/models/UserVerificationEnum"; |  | ||||||
|  |  | ||||||
| import { t } from "@lingui/macro"; | import { t } from "@lingui/macro"; | ||||||
|  |  | ||||||
| import { TemplateResult, html } from "lit"; | import { TemplateResult, html } from "lit"; | ||||||
| @ -14,6 +12,7 @@ import { | |||||||
|     FlowsInstancesListDesignationEnum, |     FlowsInstancesListDesignationEnum, | ||||||
|     ResidentKeyRequirementEnum, |     ResidentKeyRequirementEnum, | ||||||
|     StagesApi, |     StagesApi, | ||||||
|  |     UserVerificationEnum, | ||||||
| } from "@goauthentik/api"; | } from "@goauthentik/api"; | ||||||
|  |  | ||||||
| import { DEFAULT_CONFIG } from "../../../api/Config"; | import { DEFAULT_CONFIG } from "../../../api/Config"; | ||||||
|  | |||||||
| @ -44,7 +44,12 @@ export class InvitationForm extends ModelForm<Invitation, string> { | |||||||
|  |  | ||||||
|     renderForm(): TemplateResult { |     renderForm(): TemplateResult { | ||||||
|         return html`<form class="pf-c-form pf-m-horizontal"> |         return html`<form class="pf-c-form pf-m-horizontal"> | ||||||
|             <ak-form-element-horizontal label=${t`Name`} ?required=${true} name="name"> |             <ak-form-element-horizontal | ||||||
|  |                 ?slugMode=${true} | ||||||
|  |                 label=${t`Name`} | ||||||
|  |                 ?required=${true} | ||||||
|  |                 name="name" | ||||||
|  |             > | ||||||
|                 <input |                 <input | ||||||
|                     type="text" |                     type="text" | ||||||
|                     value="${this.instance?.name || ""}" |                     value="${this.instance?.name || ""}" | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Jens Langhammer
					Jens Langhammer