Skip to content

Allow registering a UI element for a typed form path #156

Description

@ap32

Formisch works especially well across component boundaries because separate components can coordinate through the same form store and schema-derived path.

I have a similar need for DOM references.

One component performs a form operation, while another component—possibly several levels deeper—renders the UI associated with the affected form path. The initiating component may then need to scroll that UI into view, focus it, measure it, highlight it, or perform another application-specific action.

At the moment, this requires a separate reference store, emitting references through component boundaries, querying the DOM, or depending on the component structure. These approaches duplicate part of Formisch’s path-based coordination and tend to become fragile when the UI structure changes.

I do not think a container or block should become a Field. A field can remain the final form unit. The missing concept would instead be an optional UI target associated with any valid form path.

A possible low-level API could be:

setTarget(form, {
  path,
  target,
});

getTarget(form, {
  path,
});

In Vue, registration could work through a callback ref:

<section
  :ref="target =>
    setTarget(form, {
      path,
      target,
    })
  "
>
  <!-- UI associated with the path -->
</section>

Another component holding the same form and path could retrieve the target:

const target = getTarget(form, { path });

target?.scrollIntoView({
  behavior: 'smooth',
  block: 'nearest',
});

Scrolling is only one example. Formisch would not necessarily need to provide scrollIntoView, customizable focus behavior, or any other specific UI operation. The primitive would simply make the registered target available through the same form-plus-typed-path model already used by the rest of Formisch.

This would preserve the distinction:

  • a field is the final form unit;
  • a target is optional UI metadata associated with a form path.

The exact names and API shape are only illustrative. The main request is a form-scoped and type-safe way to register and retrieve an element across component boundaries.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions