inertiajs / inertia

Inertia.js lets you quickly build modern single-page React, Vue and Svelte apps using classic server-side routing and controllers.
https://inertiajs.com
MIT License
6.02k stars 405 forks source link

Form defaults() then reset() doesn't work as expected #1862

Open fufaldinav opened 2 months ago

fufaldinav commented 2 months ago

Version:

Describe the problem:

The form does not reset isDirty state after calling defaults() and then calling reset() This behavior is observed if there are only primitive values in the form I assume that watcher doesn't see changes and does not change the IsDirty state

watch(
  form,
  (newValue) => {
    form.isDirty = !isEqual(form.data(), defaults)
    if (rememberKey) {
      router.remember(cloneDeep(newValue.__remember()), rememberKey)
    }
  },
  { immediate: true, deep: true },
)

Steps to reproduce:

Create a form as in the playground:

const form = useForm('NewUser', {
  name: '',
  company: '',
  role: '',
})

Try to change some value

image

Next, call defaults() and reset(), isDirty will not change its state

https://github.com/inertiajs/inertia/assets/1456499/81c37c7e-c0d9-4c7d-8c5b-9e8e27574674