Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A solid reactive handling of initialValues #268

Open
SirbyAlive opened this issue Sep 19, 2023 · 0 comments
Open

A solid reactive handling of initialValues #268

SirbyAlive opened this issue Sep 19, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@SirbyAlive
Copy link
Contributor

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.

@SirbyAlive SirbyAlive added the enhancement New feature or request label Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant