Skip to content

as("hidden") should allow omitting the value when the field manages its own state #15887

Description

@Stadly

Describe the problem

When using as("hidden") on a remote form field, the value parameter is required — both at the type level (AsArgs) and at runtime (throws in DEV if missing). This forces redundant patterns when the field already manages its own state:

<input {...form.fields.id.as("hidden", form.fields.id.value() ?? "")} />

Other types (text, number, etc.) allow omitting the second argument, in which case they use get_value() internally. Hidden inputs should work the same way.

Describe the proposed solution

Make the value parameter optional for as("hidden"). When omitted, use get_value() (the reactive form state) just like as("text") does:

<!-- Current (required, redundant): -->
<input {...form.fields.id.as("hidden", form.fields.id.value() ?? "")} />

<!-- Proposed (optional, uses field state): -->
<input {...form.fields.id.as("hidden")} />

The explicit value should still be supported for cases where you want to pass an external value (e.g. a prop):

<input {...form.fields.appId.as("hidden", appId)} />

The name prefix (n: for numbers, b: for booleans) can be derived from get_value() at construction time when no explicit value is provided.

Alternatives considered

  • Keep the explicit value pattern (current behavior) — works but is verbose and redundant when the field already holds the value via .set()
  • Use as("text") and manually add type="hidden":
    <input {...form.fields.id.as("text")} type="hidden" />
    This works since the type attribute overrides the spread, but is a non-obvious workaround that relies on attribute ordering.

Importance

would make my life easier

Additional Information

Related: #14694 (type restrictions for hidden), #15566 / #15577 (declarative values for other types)

SvelteKit 2.60.1, relevant code: src/runtime/form-utils.js lines 711–722

Activity

  1. added
    formsStuff relating to forms and form actions
    on May 22, 2026
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

    formsStuff relating to forms and form actions

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions