Skip to content

Commit 2fc826c

Browse files
committed
feat: Add custom widget handler for object
1 parent 1e082e4 commit 2fc826c

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

packages/form/src/triage/object.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ export const fieldObject = (
1717
if (typeof schema.properties !== 'object')
1818
return widgets.callout?.({ id: '', message: error }) ?? html`${error}`;
1919

20+
const id = path.join('.');
21+
22+
function missing(widgetName: string) {
23+
const options = { id, message: `Missing ${widgetName} widget.` };
24+
return widgets?.callout?.(options) ?? html`<p>${options.message}</p>`;
25+
}
26+
2027
const children = Object.entries(schema.properties).map(
2128
([propName, propValue]) => {
2229
if (Array.isArray(propValue) || typeof propValue === 'boolean')
@@ -59,13 +66,18 @@ export const fieldObject = (
5966
if (typeof uiSchema?.['ui:title'] === 'string') label = uiSchema['ui:title'];
6067

6168
const options = {
62-
id: path.join('.'),
69+
id,
6370
label,
6471
helpText: schema.description,
6572
children,
6673
level,
6774
};
6875

76+
if (typeof uiSchema?.['ui:widget'] === 'string') {
77+
const customWidgetName = uiSchema?.['ui:widget'];
78+
return widgets?.[customWidgetName]?.(options) || missing(customWidgetName);
79+
}
80+
6981
return (
7082
widgets?.object?.(options) ??
7183
widgets?.callout?.({ id: '', message: error }) ??

packages/form/src/triage/primitive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export const fieldPrimitive = (
189189
if (typeof uiOptions?.['ui:widget'] === 'string') {
190190
const customWidgetName = uiOptions?.['ui:widget'];
191191
if (customWidgetName !== 'password') {
192-
return widgets?.[customWidgetName]?.(options) || missing('custom');
192+
return widgets?.[customWidgetName]?.(options) || missing(customWidgetName);
193193
}
194194
}
195195

0 commit comments

Comments
 (0)