-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathattribute-input.ts
More file actions
51 lines (45 loc) · 1.76 KB
/
attribute-input.ts
File metadata and controls
51 lines (45 loc) · 1.76 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
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* Copyright (c) 2025 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 { AttributeInputCallback } from '@forgerock/journey-client/types';
export default function attributeInputComponent(
journeyEl: HTMLDivElement,
callback: AttributeInputCallback<string | number | boolean>,
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();
// Determine input type based on attribute type
const attributeType = callback.getType();
if (attributeType === 'BooleanAttributeInputCallback') {
input.type = 'checkbox';
input.checked = (callback.getInputValue() as boolean) || false;
} else if (attributeType === 'NumberAttributeInputCallback') {
input.type = 'number';
input.value = String(callback.getInputValue() || '');
} else {
input.type = 'text';
input.value = String(callback.getInputValue() || '');
}
input.id = collectorKey;
input.name = collectorKey;
input.required = callback.isRequired();
journeyEl?.appendChild(label);
journeyEl?.appendChild(input);
journeyEl?.querySelector(`#${collectorKey}`)?.addEventListener('input', (event) => {
const target = event.target as HTMLInputElement;
if (attributeType === 'BooleanAttributeInputCallback') {
callback.setInputValue(target.checked);
} else if (attributeType === 'NumberAttributeInputCallback') {
callback.setInputValue(Number(target.value));
} else {
callback.setInputValue(target.value);
}
});
}