felte
felte copied to clipboard
A solid reactive handling of `initialValues`
Is your feature request related to a problem? Please describe.
The two means to provide initialValues
are not consistent on updates (eg: after a successful submit):
- config property
initialValues
ignores any updates after the initial call. - input
value
prop visually reacts to updates but the underlying form data is not updated.
Describe the solution you'd like
I would like the initialValues
to accept an accessor in the shape of an accessor function:
initialValues: () => ({
myField: data().myField,
})
That is evaluated in a solid-js createEffect
.
My current workaround is:
const { form, setInitialValues, reset } = createForm();
createEffect(() => {
setInitialValues(data());
reset();
});
Its benefits are:
- it does load a synchronous initial state
- it does react to subsequent changes to the initial state
- it does reset the dirty flag (which the prop
value
does not) - it does update the underlying form data (which the prop
value
does not)
Cons:
- Still not consistent with the
value
behavour
This could easily be added to @felte/solid create-form
, given that it is a behaviour that would be coherent with the rest of the project. But I fear this shortcuts behaviours from the core package.