Skip to content

Reactive remote form field.value() #14680

@bdmackie

Description

@bdmackie

Describe the problem

I often use a hidden input field as a backing field for a complex UI control like a date picker.

Before Field Proxies

Previously I'd bind to a rune (acting like a shadow dom to the form) and it all worked as I expect.

// script
const data = $state({name: 'Bob'; birthdate: Date.now()});
<!--- template --->
<input name="category" type="hidden" value={data.birthdate} />
<MyDatePicker bind:value={data.birthdate} />
<p>Debug birthdate: {data.birthdate}</p>

Attempt After Field Proxies

With the new field proxy, I thought I could do away with the rune 'shadow DOM' and use the field.value() and field.set() methods. This treats the field itself as the source of truth.

// script
const data = $state({name: 'Bob'; birthdate: Date.now()});
<!--- template --->
<input name="birthdate" type="hidden" value={form.fields.birthdate.value()} />
<MyDatePicker bind:value={() => form.fields.birthdate.value(), (v) => form.fields.birthdate.set(v)} />
<p>Debug birthdate: {form.fields.birthdate.value()}</p>

Observations/Problems

  1. Updates to the date picker calls field.set() but DOES NOT cause the input value to update.
  2. BUT: Logging a call to field.value() immediately after the call to field.set() DOES show the updated value.
  3. HOWEVER: Submitting the form DOES NOT show the updated value in the result. - !!! BUG?
  4. The debug line also does NOT update.

Describe the proposed solution

My preference is that any rendering of field.value() is reactive, i.e. any calls to field.set() will cause anything else referring to field.value() to update.

Alternatives considered

The alternative would be to continue using a rune shadow DOM, but that seems to reduce the simplification value of the form proxies substantially.

.... or perhaps another approach that I'm unaware of?

Importance

would make my life easier

Additional Information

No response

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