diff --git a/web/src/elements/SearchSelect.ts b/web/src/elements/SearchSelect.ts index 78ce3f8bb..6b056b98b 100644 --- a/web/src/elements/SearchSelect.ts +++ b/web/src/elements/SearchSelect.ts @@ -40,7 +40,7 @@ export class SearchSelect extends LitElement { renderElement!: (element: T) => string; @property({ attribute: false }) - value!: (element: T) => unknown; + value!: (element: T | undefined) => unknown; @property({ attribute: false }) selected!: (element: T) => boolean; diff --git a/web/src/elements/forms/Form.ts b/web/src/elements/forms/Form.ts index 1053c050e..61d5ea335 100644 --- a/web/src/elements/forms/Form.ts +++ b/web/src/elements/forms/Form.ts @@ -153,7 +153,11 @@ export class Form extends LitElement { json[element.name] = element.checked; } else if (element.tagName.toLowerCase() === "ak-search-select") { const select = element as unknown as SearchSelect; - json[element.name] = select.value(select.selectedObject); + try { + json[element.name] = select.value(select.selectedObject); + } catch { + console.debug("authentik/form: SearchSelect.value error"); + } } else { for (let v = 0; v < values.length; v++) { this.serializeFieldRecursive(element, values[v], json); diff --git a/web/src/pages/policies/PolicyBindingForm.ts b/web/src/pages/policies/PolicyBindingForm.ts index 651aabd0d..eca07d05c 100644 --- a/web/src/pages/policies/PolicyBindingForm.ts +++ b/web/src/pages/policies/PolicyBindingForm.ts @@ -222,8 +222,8 @@ export class PolicyBindingForm extends ModelForm { .renderElement=${(group: Group): string => { return group.name; }} - .value=${(group: Group): string => { - return group.pk; + .value=${(group: Group | undefined): string => { + return group ? group.pk : ""; }} .selected=${(group: Group): boolean => { return group.pk === this.instance?.group; @@ -256,8 +256,8 @@ export class PolicyBindingForm extends ModelForm { .renderElement=${(user: User): string => { return UserOption(user); }} - .value=${(user: User): number => { - return user.pk; + .value=${(user: User | undefined): number => { + return user ? user.pk : 0; }} .selected=${(user: User): boolean => { return user.pk === this.instance?.user;