Skip to content

Form generator: tristate-aware blank-optional field submit handling #223

Closed

Description

@dmealing

Deferred from the form-controls view-dispatch cycle (spec: docs/superpowers/specs/2026-07-18-form-controls-view-dispatch-design.md).

A generated form's blank optional scalar inputs submit "" (empty string). For a nullable date/timestamp column this is invalid, and a != null check misreads "" as "set". A downstream implementation worked around this by deleting ""-valued keys from the submit payload. That fix was not promoted because it conflicts with FR-035 present-key PATCH tristate: deleting a cleared field's key means "untouched", so on the edit/PATCH path clearing a previously-set optional field silently fails to clear it.

The correct behavior is tristate-aware and needs create-vs-edit + dirty-state awareness:

  • blank on CREATE → omit the key (or send null) so the column defaults/NULLs,
  • a field that was set and is now cleared on EDIT → send explicit null (present-null clears),
  • a @required field left untouched → unchanged.

Scope: the generated form's submit handler in codegen-ts-react (and its React runtime binding). Until this lands, the promoted form template inherits the pre-existing ""-vs-NULL wart for blank optional date/timestamp inputs on CREATE.

Activity

  1. added
    enhancement
    on Jul 19, 2026
  2. dmealing commented on Aug 23, 2026

    @dmealing
    MemberAuthor

    Fixed on main in af6bd30 + 5e0b13f, shipping in 0.24.1.

    Implemented as the tristate you specified, keyed on defaultValues (what already
    distinguishes the modes since #227):

    • CREATE — the blank key is OMITTED, so the column's DEFAULT/NULL applies.
    • EDIT — it is sent as explicit null, which CLEARS the column.

    So the FR-035 conflict is avoided rather than traded: deleting the key on the edit path is
    exactly what loses the clear.

    Scope is decided at codegen time. @required is excluded (blank there is a validation
    error the schema owns, and rewriting it would turn a caught error into a silent null), as
    are controls that cannot produce "" — checkbox, view.image, nested field.object and
    array fields. An entity with no blankable optional field emits no normalizer, so its output
    stays byte-identical.

    The tests EXECUTE the emitted normalizer rather than grepping for it.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions