* web/elements: only render form once instance is loaded Signed-off-by: Jens Langhammer <jens@goauthentik.io> * use radio for transport Signed-off-by: Jens Langhammer <jens@goauthentik.io> * only wait for instance to be loaded if set Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add hook to load additional data in form Signed-off-by: Jens Langhammer <jens@goauthentik.io> * make send an abstract function instead of attribute Signed-off-by: Jens Langhammer <jens@goauthentik.io> * ensure form is updated after data is loaded Signed-off-by: Jens Langhammer <jens@goauthentik.io> * remove until for select and multi-selects in forms Signed-off-by: Jens Langhammer <jens@goauthentik.io> * don't use until for file uploads Signed-off-by: Jens Langhammer <jens@goauthentik.io> * remove last until from form Signed-off-by: Jens Langhammer <jens@goauthentik.io> * remove deprecated import Signed-off-by: Jens Langhammer <jens@goauthentik.io> * prevent form double load, add error handling for PreventFormSubmit Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix double creation of inner element in proxy form Signed-off-by: Jens Langhammer <jens@goauthentik.io> * make PreventFormSubmit work correctly Signed-off-by: Jens Langhammer <jens@goauthentik.io> --------- Signed-off-by: Jens Langhammer <jens@goauthentik.io>
53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
import { Form } from "@goauthentik/elements/forms/Form";
|
|
|
|
import { TemplateResult, html } from "lit";
|
|
import { customElement, property } from "lit/decorators.js";
|
|
|
|
@customElement("ak-proxy-form")
|
|
export abstract class ProxyForm extends Form<unknown> {
|
|
@property()
|
|
type!: string;
|
|
|
|
@property({ attribute: false })
|
|
args: Record<string, unknown> = {};
|
|
|
|
@property({ attribute: false })
|
|
typeMap: Record<string, string> = {};
|
|
|
|
innerElement?: Form<unknown>;
|
|
|
|
async submit(ev: Event): Promise<unknown | undefined> {
|
|
return this.innerElement?.submit(ev);
|
|
}
|
|
|
|
resetForm(): void {
|
|
this.innerElement?.resetForm();
|
|
}
|
|
|
|
getSuccessMessage(): string {
|
|
return this.innerElement?.getSuccessMessage() || "";
|
|
}
|
|
|
|
async requestUpdate(name?: PropertyKey | undefined, oldValue?: unknown): Promise<unknown> {
|
|
const result = await super.requestUpdate(name, oldValue);
|
|
await this.innerElement?.requestUpdate();
|
|
return result;
|
|
}
|
|
|
|
renderVisible(): TemplateResult {
|
|
let elementName = this.type;
|
|
if (this.type in this.typeMap) {
|
|
elementName = this.typeMap[this.type];
|
|
}
|
|
if (!this.innerElement) {
|
|
this.innerElement = document.createElement(elementName) as Form<unknown>;
|
|
}
|
|
this.innerElement.viewportCheck = this.viewportCheck;
|
|
for (const k in this.args) {
|
|
this.innerElement.setAttribute(k, this.args[k] as string);
|
|
(this.innerElement as unknown as Record<string, unknown>)[k] = this.args[k];
|
|
}
|
|
return html`${this.innerElement}`;
|
|
}
|
|
}
|