svelte-forms-lib icon indicating copy to clipboard operation
svelte-forms-lib copied to clipboard

Conserve previous values when using updateInitialValues

Open mcmxcdev opened this issue 4 years ago • 1 comments

Is your feature request related to a problem? Please describe. Currently, updateInitialValues only reassigns whatever you pass it into a new object. All previous values are lost.

In my opinion, most of the time updateInitialValues is used to get updated values from an API endpoint, where you might only want to change a subset of the initialValues, similar to a PATCH request.

Describe the solution you'd like Change the behavior of updateInitialValues to spread new values in and combine those with the same key naming. This would be more the behavior that at least I expect from it.

Describe alternatives you've considered An alternative would be to spread the previous values myself, but this requires to have them available easily and sometimes means passing parameters across multiple methods potentially.

Additionally, there is no documentation for updateInitialValues on the website, it would be great to have it!

mcmxcdev avatar Jan 18 '21 16:01 mcmxcdev

Ideally, you will want to use$form as spread operator in updateInitialValues. For example:

updateInitialValues({
  ...$form
  propertyName: updateValue
})

islanderTron avatar May 16 '22 19:05 islanderTron