Skip to content

FormFieldLight doesn't pass autocomplete config to registered components #11

@stmh

Description

@stmh

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 fetching
  • debounceMs - debounce delay for typing
  • fetchOnFocus - whether to load initial suggestions on focus
  • allowFreeText - whether to accept values not in suggestions

Problem

  1. Autocomplete doesn't work out of the box: Despite the schema supporting format: "autocomplete", the field renders as a plain text input. The autocompleteMatcher is exported but no autocomplete component is registered by default.

  2. Manual registration doesn't help: When manually registering a custom autocomplete component via the field registry, FormFieldLight does not pass the autocomplete configuration 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

  1. Register a default autocomplete component that handles format: "autocomplete" fields, or
  2. 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)}
/>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions