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
useFieldParam #4742
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
Yes, the feature request is related to the problem of synchronizing form field values with URL parameters. Currently, in
vee-validate
, there is no built-in way to bind form field values to URL parameters. This can be frustrating when trying to create a form where the state needs to be preserved in the URL, such as in a filter form on a search page.Describe the solution you'd like
The solution is a composable function
useFieldParam
that provides two-way binding between URL parameters and avee-validate
field. It uses theuseField
function fromvee-validate
and theuseUrlSearchParams
function from@vueuse/core
to achieve this. This function takes the fieldname
, validation rules, and options as arguments and returns a reactive object representing thevee-validate
field, with two-way binding to the corresponding URL parameter.Here's a rough implementation of this composable:
Describe alternatives you've considered
An alternative solution could be to manually watch the field values and update the URL parameters accordingly, and vice versa. However, this can lead to a lot of repetitive code if there are many fields that need to be synchronized with URL parameters. The
useFieldParam
composable abstracts this logic away and makes it reusable, leading to cleaner and more maintainable code.The text was updated successfully, but these errors were encountered: