-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Summary
Autocomplete fields as defined in PR #10 do not work out of the box. When a field schema specifies format: "autocomplete" with an autocomplete configuration, the field renders as a plain text input instead of an autocomplete field with suggestions.
Context: Autocomplete vs Select with Dynamic Options
An autocomplete field is fundamentally different from a select field with dynamic options:
- Autocomplete: Text input with type-ahead suggestions fetched from an API. Supports free-text entry (optionally), debounced search-as-you-type, and is suited for large datasets where loading all options upfront isn't practical.
- Select with dynamic options: Dropdown that loads all options from an API on focus/mount. User picks from a finite list. Not suited for large datasets.
The AutocompleteConfig supports features specific to autocomplete behavior:
minChars- minimum characters before fetchingdebounceMs- debounce delay for typingfetchOnFocus- whether to load initial suggestions on focusallowFreeText- whether to accept values not in suggestions
Problem
-
Autocomplete doesn't work out of the box: Despite the schema supporting
format: "autocomplete", the field renders as a plain text input. TheautocompleteMatcheris exported but no autocomplete component is registered by default. -
Manual registration doesn't help: When manually registering a custom autocomplete component via the field registry,
FormFieldLightdoes not pass theautocompleteconfiguration to the registered component.
In FormFieldLight.svelte (lines 227-244), registered components receive these props:
<registeredComponent.component
id={fieldKey}
{value}
placeholder={schema.placeholder ?? ''}
{required}
ariaDescribedBy={descriptionId}
height={schema.height as string | undefined}
darkTheme={schema.darkTheme as boolean | undefined}
autoFormat={schema.autoFormat as boolean | undefined}
...
onChange={(val: unknown) => onChange(val)}
/>The autocomplete property from schema.autocomplete is not passed. A registered autocomplete component cannot access its configuration (url, fetchOnFocus, labelField, valueField, etc.).
Expected Behavior
A field defined with format: "autocomplete" should render as an autocomplete input that fetches suggestions from the configured URL.
Reproduction
Define a field with autocomplete config in the node schema:
{
"type": "string",
"format": "autocomplete",
"autocomplete": {
"url": "/api/secrets/options",
"fetchOnFocus": true,
"labelField": "label",
"valueField": "value"
}
}Result: Field renders as a plain text input with no autocomplete behavior.
Suggested Fix
- Register a default autocomplete component that handles
format: "autocomplete"fields, or - At minimum, pass
autocomplete={schema.autocomplete}to registered components so users can provide their own implementation:
<registeredComponent.component
id={fieldKey}
{value}
autocomplete={schema.autocomplete}
...
onChange={(val: unknown) => onChange(val)}
/>