Comments (6)
Well I would guess that is correct, the value is commited from the form when a new dom element is added to it to all children so they run their validations correctly.
from formkit.
How does running validations corresponds to triggering one of the input's v-model
event? This feels counter-intuitive (even though you might be totally right with the above!), as to me these are two different aspects. The value of the first input changes only once, yet it appears as if changed twice based on the console output.
Due to this behavior there doesn't seem to be a straightforward way to reliably hook a watcher and run some logic when the combobox'es value actually changes.
from formkit.
The value doesn't change, but it does trigger a commit
, when any value from a parent changes it spreads to its children so those values can be passed to the validation, meaning when you add a value to the form, it triggers a commit that goes to all children, you can read more about it here: https://formkit.com/essentials/architecture#value-settlement
from formkit.
@DamianGlowala — it isn’t really related to validation, but you are correct in general, there is intentionally no event like @change
in FormKit. Why? Well — there are a number of reasons:
- Knowing if something changed is expensive. Of course this doesn’t seem true at a surface level, comparing two strings is pretty cheap after all, but comparing deeply nested objects is expensive, especially if the property being manipulated is deep.
- Change ownership. Usually what people mean when they talk about "Did this input change" is "I want to perform a side effect when the user interacts with the input". In a synced tree (like formkit) what changed the value of an input is immaterial. FormKit values can be changed by a parent node, a child, programmatically via node, with a plugin, in a hook, etc etc — the ownership of the change should not be important — the state should be important. Which brings me to the most important point:
- Declarative. FormKit tries to encourage you to write your forms declaratively. In general, I wouldn’t recommend performing effects based on changes but rather the current state of your form. For example, a form could be hydrated with a given set of values — those values should always recreate the exact state of the form, irregardless of how a user interacted with the form. Event tracking is a slipper slope that often gets your form working in one "view" of your data, but will break when the same state is re-created by another means.
So yeah, in general events in FormKit are noisy — most of the time when people are worried about how many times their event fn is called, I get worried about how the form is structured. That being said, we’re always trying to make FormKit better so if there are valid declarative use cases that aren’t considered please let us know, or if there is some kind of state we aren’t already tracking that we should — also let us know :)
from formkit.
Also if you use the FormKit event system instead of v-model it might mitigate some noisy behaviour: https://formkit.link/0f7a4300993e422d60d1121f5275e304
from formkit.
Thank you both for thorough explanation and provided example!
It's nevertheless interesting how the node's commit
event is triggered once (yay!), but the v-model
twice. This is still a discrepancy I haven't fully grasped, but if this is how things need to be done - I have nothing else but to accept it without any further questions! 😄 The below { ..., __init: true }
is the only thing I can noticeably spot that gets added and probably triggers the v-model
more than just once (it's purely my guess without diving deeper). Potentially 'stupid' question appears in my mind: why isn't it emitted with __init
when it is triggered for the first time? Is this how things definitely need to be left?
I'll think about the points you raised Justin about the declarativeness, appreciate these. There might be a room for improvement. Will report soon with any findings, or if I have none backing up this issue, I'll happily close it.
from formkit.
Related Issues (20)
- File Input FormKit element resetting bug
- Transfer List Max Not Working HOT 1
- Multiple Formkit with same schema HOT 2
- Dark mode text hard to read (select type) HOT 2
- Docs say wrong number of arguments for createInput
- Blurred state stays false
- Hydration warnings on page refresh using Radio in a List HOT 3
- The autocomplete selection does not appear the second time HOT 5
- Make ShowMask property reactive
- Сursor jumps to the beginning of the value in the float input field while erasing
- Naked `floating-label` attribute on FormKit component does not work HOT 1
- Delay prop being overridden (to zero) by parent nodes
- Inputs break all component slots except `default` HOT 3
- `v-if` not working on messages empty object HOT 1
- FormKit Pro not synced with the current version HOT 2
- Categories in transfer list component
- Unable to use `$remove:` in a schema definition HOT 2
- Allow disabling types for default FormKit inputs HOT 1
- Custom taglist validation error only shows up when you focus out HOT 1
- Nuxt Layers and FormKit theme HOT 6
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.