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
In short - even though initialValue supports being passed as a ref it doesn't seem to bring any value. After doing an API call I'm changing the the value of initialValue ref and... nothing happens. Not only the value of the field stays the same (even though I - as a user - didn't touched it yet), but also the dirty state stays unchanged.
Describe the solution you'd like
I would propose to change the way initialValue changes are being handled.
When there was no interaction with the field whatsoever (meta.touched or meta.dirty are false) the new value of initialValue should be propagated directly to the value of the field - so there is no need for resetting the field after every API call.
resetField should use current value of initialValue when value field is not provided.
meta.dirty should be reevaluated every time initialValue changes.
Describe alternatives you've considered
Currently I need to run resetField every time I fetch data from the API (which becomes pretty tedious when having multiple fields and multiple API calls in the same file). Also I need to pass value of initialValue every time I run resetField - it seems that resetField ignores initialValue. https://codesandbox.io/s/basic-example-composition-api-forked-ubxk88?file=/src/App.vue:405-701
I know that I've described 3 things here, so if you believe only some of them should be introduced - please write about that.
Also - I'm willing to write a PR changing this.
The text was updated successfully, but these errors were encountered:
The behavior you are asking for is actually implemented but only works if the field is part of a form context and the initial values are controlled by the form.
Whether or not it should be implemented on the single field level, I think it makes sense to be consistent with the form behavior and make it work similarly. I will see what I can do, if you would like to try PR then go for it! Just remember you need to do it for the useField only as useForm already has this implemented.
@logaretm Hey, thanks for the response! Ofc I'll give it a try - if you have any additional suggestions just shoot them my way. If everything goes smoothly I should file a PR this week.
Is your feature request related to a problem? Please describe.
Current behaviour of
initialValue
is a bit problematic for the async use cases. I've tried to show it on this example:https://codesandbox.io/s/basic-example-composition-api-forked-u2pc93?file=/src/App.vue:303-572
In short - even though
initialValue
supports being passed as a ref it doesn't seem to bring any value. After doing an API call I'm changing the the value ofinitialValue
ref and... nothing happens. Not only the value of the field stays the same (even though I - as a user - didn't touched it yet), but also thedirty
state stays unchanged.Describe the solution you'd like
I would propose to change the way
initialValue
changes are being handled.meta.touched
ormeta.dirty
are false) the new value ofinitialValue
should be propagated directly to thevalue
of the field - so there is no need for resetting the field after every API call.resetField
should use current value ofinitialValue
whenvalue
field is not provided.meta.dirty
should be reevaluated every timeinitialValue
changes.Describe alternatives you've considered
Currently I need to run
resetField
every time I fetch data from the API (which becomes pretty tedious when having multiple fields and multiple API calls in the same file). Also I need to pass value ofinitialValue
every time I runresetField
- it seems thatresetField
ignoresinitialValue
.https://codesandbox.io/s/basic-example-composition-api-forked-ubxk88?file=/src/App.vue:405-701
I know that I've described 3 things here, so if you believe only some of them should be introduced - please write about that.
Also - I'm willing to write a PR changing this.
The text was updated successfully, but these errors were encountered: