-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can the initialValue
of useForm
be populated with a ref?
#23
Comments
Thank you very much for sharing your thoughts. Indeed, the initial version of Vorms didn't consider passing a Here's the current idea: // This is a `Reactive` or `Ref`
const searchParams = useRouteQuery()
const { values, dirty } = useForm({
initialValues: searchParams
}) If However, if possible, I would also appreciate having more use cases for this solution, as it would be great to apply it to different scenarios. Additionally, based on the scenario you provided, perhaps directly binding the |
So, if I understand correctly, you're suggesting that I can skip using the |
Yes, based on the scenario you provided, using Vorms may not make your problem simpler. Especially in your example: const { values } = useForm({
initialValues: {
// search is a `Ref`
search: search,
}
} If If Additionally, if you want to perform validation while typing, you can use it like this: const { register } = useForm({
initialValues: searchParams,
validateMode: 'change', // or 'input'
})
// need to bind value and attributes on the input field
const { value, attrs } = register('keyword') However, it still requires waiting for Vorms to support passing a I apologize if I didn't directly solve your problem, but I appreciate the suggestions you provided as they gave me some interesting ideas. |
Regarding the idea you presented, I believe I may require a more flexible design to separately define the reactive route query and useForm's initialValues. For instance, when it comes to the "page" parameter, I do not need to validate it, so the structure of routeQuery might differ from that of initialValues: // This is a `Reactive`
const routeQuery = useRouteQuery({
search: route.query.search,
page: route.query.page,
})
const { values } = useForm({
initialValues: {
search: toRef(routeQuery, "search"),
}
})
const { products, pending, error, refresh } = await useProducts({
params: {
search: toRef(routeQuery, "search"),
page: toRef(routeQuery, "page"),
}
}) No worries, I may allocate some time to study this functionality. When designing the export function useTitle(
newTitle: MaybeRef<string | null | undefined> = null,
...
) {
...
const title = ref(newTitle ?? document?.title ?? null)
} |
Thank you for your assistance, and I'm looking forward to the results of your study as well! 💚 Additionally, I might still suggest directly passing |
Indeed, I am also uncertain whether using excessive |
@Mini-ghost Hi, kindly request your assistance in troubleshooting the problems I encountered while running |
@chnejohnson Can you please provide the version of Vue you are currently using? You can execute |
@Mini-ghost Sure |
@chnejohnson There doesn't seem to be any issue. I've tried several different environments here and couldn't reproduce the problem. I'm not sure what the reason could be. Have you considered cloning the repository again to give it a try? |
Sorry, re-cloning the project solved the problem. Thanks for your help |
Describe the feature
Greetings,
I am currently implementing a scenario using this package. In the case of searching for a product by name, I would like to have my reactive URL, reactive form, and reactive API request all share the same
ref
. The code structure would look something like this:When designing the
useProducts
function, I modified the type ofuseProductsOption.params.search
totype MaybeRef<T> = T | Ref<T>
, allowing it to accept a ref and share the same set of ref variables. I would like to inquire whether theinitialValues
ofuseForm
can achieve this functionality.Perhaps there is a better way to solve my issue of sharing the same ref? I would like to hear your suggestions.
Cheers
Additional information
The text was updated successfully, but these errors were encountered: