-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
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
- Updates to the date picker calls field.set() but DOES NOT cause the input value to update.
- BUT: Logging a call to field.value() immediately after the call to field.set() DOES show the updated value.
- HOWEVER: Submitting the form DOES NOT show the updated value in the result. - !!! BUG?
- 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