Comments (3)
@jksturgeon I think a lot of what you're bumping into is issues with v-model and it competing with the localStorage plugin for the setting of the values. While we can probably do further work to smooth out the v-model behavior here's an approach you can use to work around it and correctly hydrate the options / values without the need for a v-model.
https://formkit.link/8ce3afa87c9ad55e5ab41d3e5840177f
In this case we key
the dependent input so that it will re-render when its dependency changes. We also don't render the input at all until the dependent value is set (the v-if
) β so that we know we can compute the correct options. The options
has been switched from a computed property to a function βΒ and it will re-run when the input re-renders which should now be every time the food
input changes.
from formkit.
Thank you! This gets me a lot closer. I removed the v-if because I do want all inputs to show even if no options are available, and modified getFlavors to return an empty array if food hasn't been selected yet, thus rendering a disabled input. That works just fine for my needs.
The reason I used v-model is it makes it super easy to populate a form with default values. I'll need to read the docs more on the other options to set defaults.
In my case, on an inital form, the very first dropdown MUST be populated, and the second dropdown must have options based on that first dropdown. The rest cascade from there and it's about 6-7 levels of dependent selects. The first select is actually a company, and it must default to the company the user belongs to, which is pulled from a pinia store and not hard coded. To make it even more complicated, I also need to be able to load an entire completed form or a partial completed form from IndexedDB and set all the dropdowns to the correct values and have them all have the correct options based on the previous selects. Basically a "save as draft" and "load from draft" feature. I'm using the local storage plugin more as an auto save in case they close the browser or whatever, separate from a deliberate save as draft.
from formkit.
So, after playing with this for a day, couple more issues. It doesn't work if getFlavors is an async function if I call it like this: :options="getFlavors(value.food)"
Instead I need to call it like this: :options="getFlavors"
and get the currently selected food from within the getFlavors function.
Second, if I set any default values, regardless of the method, it fails again. Doesn't matter if it's a value prop, using node.input(), or any other method I've tried, the result is the same. It works correctly when the first select is set to the default, but if I select a different option, select a flavor, then refresh the page, the flavors selection is forgotton. I'm not sure if it's somehow related to the first issue I was having, or if I'm again using it wrong, or if it's a bug. Regardless, I think I'm going to abandon the localStorage plugin for now as that's more of a nice to have rather than a requirement. I'll revisit later when I have more time to figure it out, and open a new issue if I have anything to report. Closing this issue for now.
from formkit.
Related Issues (20)
- Dropdown/autocomplete option selection fails when using validation and auto-animate HOT 2
- Unable to use src="<imported file>" instead of script setup inside template. HOT 1
- `@formkit/icons` not properly tree shaking
- Add `inline` option to Datepicker
- Cannot override some config when using `defaultConfig`
- AutoAnimate doesn't work when used in a repeater or list type of fields
- Max prop for Dropdown input disables input when max value reached HOT 1
- A11y: removeSelection button has no text. HOT 2
- Add FormKitNode findUpwards() function HOT 3
- Datepicker `week-day-format` prop not working HOT 2
- Autocomplete: listbox accessibility issues HOT 1
- Input text - message slot prop not working HOT 1
- Dropdown family inputs do not scroll when using down arrow key HOT 1
- Submitting invalid multi-step form causes valid inputs to receive a red border HOT 2
- Suffix icon is not keyboard focusable when it has a click handler
- Drag doesn't work on nested repeater HOT 2
- Entry transition not working when floating-label=true HOT 10
- Slider in Multi-step form errors when using v-model HOT 4
- Setup is never called with Options API when using Nuxt HOT 1
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.