-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtext-input.ts
More file actions
38 lines (33 loc) · 1.25 KB
/
text-input.ts
File metadata and controls
38 lines (33 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
* Copyright (c) 2025-2026 Ping Identity Corporation. All rights reserved.
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
import type { NameCallback, TextInputCallback } from '@forgerock/journey-client/types';
export default function textComponent(
journeyEl: HTMLDivElement,
callback: NameCallback | TextInputCallback,
idx: number,
) {
const collectorKey = callback?.payload?.input?.[0].name || `collector-${idx}`;
const label = document.createElement('label');
const input = document.createElement('input');
label.htmlFor = collectorKey;
label.innerText = callback.getPrompt();
input.type = 'text';
input.id = collectorKey;
input.name = collectorKey;
if (callback.getType() === 'NameCallback') {
input.setAttribute('autocomplete', 'webauthn');
}
journeyEl?.appendChild(label);
journeyEl?.appendChild(input);
journeyEl?.querySelector(`#${collectorKey}`)?.addEventListener('input', (event) => {
if (callback.getType() === 'NameCallback') {
(callback as NameCallback).setName((event.target as HTMLInputElement).value);
} else {
(callback as TextInputCallback).setInputValue((event.target as HTMLInputElement).value);
}
});
}