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:
parent
c7a83e6182
commit
3184a64482
|
@ -9,6 +9,7 @@ import PFForm from "@patternfly/patternfly/components/Form/form.css";
|
|||
import PFFormControl from "@patternfly/patternfly/components/FormControl/form-control.css";
|
||||
import PFBase from "@patternfly/patternfly/patternfly-base.css";
|
||||
|
||||
import { convertToSlug } from "../../utils";
|
||||
import { FormGroup } from "./FormGroup";
|
||||
|
||||
@customElement("ak-form-element-horizontal")
|
||||
|
@ -48,6 +49,9 @@ export class HorizontalFormElement extends LitElement {
|
|||
@property({ attribute: false })
|
||||
errorMessages: string[] = [];
|
||||
|
||||
@property({ type: Boolean })
|
||||
slugMode = false;
|
||||
|
||||
_invalid = false;
|
||||
|
||||
@property({ type: Boolean })
|
||||
|
@ -70,6 +74,13 @@ export class HorizontalFormElement extends LitElement {
|
|||
this.querySelectorAll<HTMLInputElement>("input[autofocus]").forEach((input) => {
|
||||
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) => {
|
||||
switch (input.tagName.toLowerCase()) {
|
||||
case "input":
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import { UserVerificationEnum } from "@goauthentik/api/dist/models/UserVerificationEnum";
|
||||
|
||||
import { t } from "@lingui/macro";
|
||||
|
||||
import { TemplateResult, html } from "lit";
|
||||
|
@ -14,6 +12,7 @@ import {
|
|||
FlowsInstancesListDesignationEnum,
|
||||
ResidentKeyRequirementEnum,
|
||||
StagesApi,
|
||||
UserVerificationEnum,
|
||||
} from "@goauthentik/api";
|
||||
|
||||
import { DEFAULT_CONFIG } from "../../../api/Config";
|
||||
|
|
|
@ -44,7 +44,12 @@ export class InvitationForm extends ModelForm<Invitation, string> {
|
|||
|
||||
renderForm(): TemplateResult {
|
||||
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
|
||||
type="text"
|
||||
value="${this.instance?.name || ""}"
|
||||
|
|
Reference in a new issue