Skip to content
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

Components. Yup. It is not possible to set the default value via .default(). I can't delete fields using .strip() #4730

Open
5 tasks done
Frallen opened this issue Apr 19, 2024 · 2 comments

Comments

@Frallen
Copy link

Frallen commented Apr 19, 2024

I'm working with a component approach. I need to set default values for fields without using :validation-schema=" for Form.But the values set in default do not appear in input. This works in the Composition Api approach, but it doesn't happen here. From devtools, I see that the scheme itself was worked out successfully, but the value itself did not appear in the input. For me, initial-values from Form is an area of global data, this data may or may not be present, I would like
default values to be present.

Also, for flexibility, I would like some fields to be removed from the output object, for this I used .strip(), which also had no effect, the field ended up in the object.

image

I am attaching both examples.

Reproduction steps

  1. Use component style. Setup form.
  2. Stup yup schema Use strip and default for some fields
  3. Try to see default value
  4. Submit form. To see a field that has not been deleted when using .strip()
    ...

Version

Vue.js 3.x and vee-validate 4.x

What browsers are you seeing the problem on?

  • Firefox
  • Chrome
  • Safari
  • Microsoft Edge

Relevant log output

No response

Demo link

https://stackblitz.com/edit/nuxt-starter-xjvmlu?file=pages%2Findex.vue

Code of Conduct

@hanzelkatomas
Copy link
Sponsor

hanzelkatomas commented May 2, 2024

That's not how initial values work. If you want to pass initial values to <Form> then you have to use form's prop called initial-values.
Example:

<Form :initial-values="{ name: 'John Doe' }" />

More on:
https://vee-validate.logaretm.com/v4/api/form/#props

@Frallen
Copy link
Author

Frallen commented May 4, 2024

That's not how initial values work. If you want to pass initial values to <Form> then you have to use form's prop called initial-values. Example:

<Form :initial-values="{ name: 'John Doe' }" />

More on: https://vee-validate.logaretm.com/v4/api/form/#props

I know that this can be done and I'm using it. Below I have given a link to an example. The code uses the composition api and sets the initial values using yup. I wanted to do it this way. If there are no initial values, then default values are substituted.

Example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants