Skip to content

Add FormData integration to Input component for native form submission #329

@KlementMultiverse

Description

@KlementMultiverse

Problem

AgnosticUI's Input component doesn't participate in native HTML form submission when used inside <form> elements. Custom form inputs that don't implement FormAssociated API lose automatic inclusion in FormData and form validation chains.

Current Behavior

When an AgnosticUI Input is placed inside a <form>, calling new FormData(form) omits the input's value entirely. This breaks standard form workflows:

<form id="login">
  <AgInput name="email" />
  <button type="submit">Login</button>
</form>

<script>
  document.getElementById('login').addEventListener('submit', (e) => {
    const data = new FormData(e.target);
    console.log(data.get('email')); // null — input is invisible to FormData
  });
</script>

This forces developers to manually track input state or use framework-specific form libraries, defeating the "framework-agnostic" promise and adding friction for AI-generated forms that expect native semantics.

Why This Matters

  1. Accessibility: Screen readers and assistive tools expect inputs to behave like native <input> elements within forms
  2. AI Readiness: When Cursor, Claude, or agent-driven UI generators read the AgnosticUI source, they assume FormData integration works—hallucination risk when it doesn't
  3. Framework Portability: Developers porting forms between frameworks expect consistent form submission behavior
  4. Standards Compliance: The Form Associated Custom Elements API exists precisely for this use case

Expected Behavior

The Input component should:

  1. Implement the ElementInternals API via attachInternals()
  2. Set the form value using setFormValue() whenever the input value changes
  3. Honor the name attribute so it appears in FormData with the correct key
  4. Participate in form validation states (:invalid, :valid, :required)
  5. Respond to form.reset() and restore its initial value

Reference

Related issue: #274 (Form Associated Custom Elements) identifies this as a priority enhancement.

The Input component lives in src/components/ag/Input/ and is used across all framework implementations. This change would benefit Button (with type="submit"), FormGroup, and all dependent components.

Acceptance Criteria

  • Input element responds to new FormData(form) and includes its value
  • Input can be reset via form.reset()
  • Input participates in form validation (:invalid CSS pseudo-class works)
  • All framework implementations (Vue, React, Lit, Svelte) support the behavior
  • Documented with example showing FormData integration

Contributed by Klement Gunndu

Metadata

Metadata

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