You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As of v4.12.0 there's no way to update the initial value of a single field without breaking the rest of the form in some way.
The use cases for this are:
Loading initial values of a part of the form from a separate api endpoint
Resetting the values of a part of the form after submit when submitting is done via multiple requests
At the very least, I want to be able to do resetField('field', { value }) and have that set the initial value of the field, update the value of the field to that initial value, and have that reflected correctly in the meta.dirty flag of both the form and the field context.
Details
Before 4.12.0 there were three different ways to set the initial values of a field:
resetForm
resetField
Reactive initialValues
All of these have different behaviors some of which seem like bugs.
resetForm
When all values are passed, resets all fields to those values even if they are touched/dirty
Additionally, there's now useless code in the internal setInitialValues method that resets the values based on the touched flag of the fields, that then gets overwritten by resetForm which is the only method that callse setInitialValues.
Proposed changes
Fix bug in resetForm when passing partial values or disallow passing partial values
Fix bug in resetField so that it doesn't break meta.dirty of the form and field
Expose setInitialValues and setFieldInitialValue to allow updating the initial values of the form without resetting the values of the field. This can have a mode option with the following option values (not sure what the default should be):
keepValues - just sets the initialValues
resetValues - resets all values, same behavior as resetForm
resetPristineValues - resets values if they are not dirty/touched (similar behavior to setInitialValues right now, but also checking the dirty status).
What happened?
As of v4.12.0 there's no way to update the initial value of a single field without breaking the rest of the form in some way.
The use cases for this are:
At the very least, I want to be able to do
resetField('field', { value })
and have that set the initial value of the field, update the value of the field to that initial value, and have that reflected correctly in themeta.dirty
flag of both the form and the field context.Details
Before 4.12.0 there were three different ways to set the initial values of a field:
resetForm
resetField
initialValues
All of these have different behaviors some of which seem like bugs.
resetForm
touched
/dirty
underfined
https://codesandbox.io/p/sandbox/basic-example-composition-api-forked-kqwp7m?file=%2Fsrc%2FApp.vue%3A16%2C37resetField
touched
/dirty
meta.dirty
flag of the form being incorrect https://codesandbox.io/p/sandbox/basic-example-composition-api-forked-g42d5k?file=%2Fsrc%2FApp.vue%3A28%2C11Reactive
initialValues
touched
dirty
fieldsAdditionally, there's now useless code in the internal
setInitialValues
method that resets the values based on thetouched
flag of the fields, that then gets overwritten byresetForm
which is the only method that callsesetInitialValues
.Proposed changes
resetForm
when passing partial values or disallow passing partial valuesresetField
so that it doesn't breakmeta.dirty
of the form and fieldsetInitialValues
andsetFieldInitialValue
to allow updating the initial values of the form without resetting the values of the field. This can have amode
option with the following option values (not sure what the default should be):keepValues
- just sets the initialValuesresetValues
- resets all values, same behavior asresetForm
resetPristineValues
- resets values if they are notdirty
/touched
(similar behavior to setInitialValues right now, but also checking the dirty status).Reproduction steps
No response
Version
Vue.js 3.x and vee-validate 4.x
What browsers are you seeing the problem on?
Relevant log output
No response
Demo link
See above
Code of Conduct
The text was updated successfully, but these errors were encountered: