Comments (6)
Hi @tosling 👋
Thanks for the quality report! It turns out what you're trying to do is not a supported feature of Vue 3 itself — that is — directly v-modeling a reactive()
object. You can model on a property of a reactive object (yourReactiveObject.formValues
), but not the object itself since that would causes whole-sale replacement of the actual object. That’s why a ref works, because it is actually operating on ref.value
instead of the ref
itself.
Perhaps, if there is any action to take here, we could throw an helpful exception for users who make the same mistake (Ive done it myself a few times).
from formkit.
Closing this issue as it won't be resolved at the FormKit level and we now have some warnings in the docs to help users avoid it.
from formkit.
thanks for the super fast reply.
I think I need to dive a little deeper into FormKit's code, to fully understand the limitations or maybe find a nice solution.
In theory:
- I would expect, that FormKit (our
<FormKit type="form">
) somehow propagates the v-model value down to the children nodes (<FormKit type="input">
in our case). - Then in the child node, you assign the value via
ref.value
. - Wouldn't it be possible, to check if we have a
Ref
or aProxy
(created by reactive()) and if it's the Proxy, then access the property directly?
from formkit.
You would think so, right? Perhaps there is some way to kinda "fake" our way there to help improve the dx on that — but fundamentally it's not really how the v-model contract works. Effectively v-model takes the emitted value and directly assigns it to the value vModelValue = $emitttedValue
. This is fine when the vModelValue
is a ref, because the template compiler knows to assign it to vModelValue.value
instead of the root object, but reactive
is not wrapped to it attempts to perform a wholesale replacement of the vModelValue
itself, (which is often a const
anyway).
Coming from the options api, this would be like trying to v-model the entire $data
object, instead of a single property within it. Here’s a simple example of this at play in pure vue.
So ways to work around it? We could do what you’re saying and detect if we are working with a reactive
vs a ref
object — and then essentially not emit the update:modelValue
event, and instead directly manipulate the modelValue
— but prop manipulation is generally frowned upon and will emit warnings from Vue.
So, I'm definitely open to suggestions on how to improve this, because fundamentally I agree with you that making it magically work with reactive()
would be a much better DX, but at the moment I feel like our hands are tied — plus it's pretty easy to just use a ref()
or a property of the reactive object.
Still — open to ideas, I'll leave this open for now. 👍
from formkit.
Thanks for the excellent explantation @justin-schroeder 👍 Very valuable information.
This should at least help others facing similar situation. - and I agree, ref()
s work pretty smoothly with FormKit, although there is the necessity of .value
here and there.
Will keep thinking about a magic solution. ;)
from formkit.
This should at least help others facing similar situation. - and I agree,
ref()
s work pretty smoothly with FormKit, although there is the necessity of.value
here and there.
I think that is why vue is going to implement sugar syntax for this using Reactivity Transforms. vuejs/rfcs#369
indeed using .value everywhere is quite ugly.
from formkit.
Related Issues (20)
- Non-functional / non-reactive properties for Rating input
- TS issue on FormKitMessages component
- [BUG] SSR + v-model + local Storage HOT 3
- Select element remains in placeholder state when option selected using option groups with placeholder set
- valid state only correctly changes when other inputs are present HOT 1
- Repeater sortability not functioning properly HOT 1
- It is impossible to add a new tag if there is already a tag in the options with the same root or a part that matches the text of the new tag in taglist field HOT 2
- Clicking on this area will not trigger the Select menu
- formkit/i18n: Validation rule's message is incorrect when using array syntax for the validation
- `autocomplete`: Async options not filterable HOT 5
- Mask input and autocomplete failing validation HOT 1
- Errors don't show with more groups HOT 3
- Repeater should consistently render when the default slot is empty HOT 1
- Mixed order of identical items in dynamic list
- <FormKit type="mask"> renders <input type="mask"> HOT 3
- datetime-local field with initial value resets itself in firefox after the entry of a 0
- FormKit datepicker component: enter key submits the form and display the calendar popup
- `childRemoved` event not triggered for type list HOT 1
- setting Buddist locale breaks datepicker HOT 2
- Changing `datepicker` value makes it to autofocus on Safari
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from formkit.