diff --git a/UI/Web/src/app/settings/_components/setting-switch/setting-switch.component.ts b/UI/Web/src/app/settings/_components/setting-switch/setting-switch.component.ts index 530fa2ff3..e39b6beee 100644 --- a/UI/Web/src/app/settings/_components/setting-switch/setting-switch.component.ts +++ b/UI/Web/src/app/settings/_components/setting-switch/setting-switch.component.ts @@ -51,7 +51,7 @@ export class SettingSwitchComponent implements AfterContentInit { const inputElement = element.querySelector('input'); // If no id, generate a random id and assign it to the input - inputElement.id = crypto.randomUUID(); + inputElement.id = this.generateId(); if (inputElement && inputElement.id) { this.labelId = inputElement.id; @@ -62,4 +62,13 @@ export class SettingSwitchComponent implements AfterContentInit { }); } + private generateId(): string { + if (crypto && crypto.randomUUID) { + return crypto.randomUUID(); + } + + // Fallback for browsers without crypto.randomUUID (which has happened multiple times in my user base) + return 'id-' + Math.random().toString(36).substr(2, 9) + '-' + Date.now().toString(36); + } + }