Skip to content

useFieldArray and useField boolean value gets pruned #5094

@Iklon

Description

@Iklon

What happened?

With help of 3 basic composables from Vee-validate (useForm, useField, useFieldArray) I can create about any form one can think of.

But I stumbled upon a bug that occurs, when the useFieldArray is combined with useField only for boolean values.

Imagine following structure:

type User = {
    name: string
    roles: Role[]
    enabled: boolean
}
type Role = {
    text: string,
    isDefault: boolean
}

When a form like this gets created, everything works fine exept the isDefault attribute. When the value of isDefault is false the attribute doesnt get to the submitted values at all, it just gets pruned. No matter if the false value got there from initialValues or it was set by user.

I dont see any reason why the attribute isDefault should get pruned based on the value. If it meets the conditions from validation and it got registered to the form via useField, it should be present in the final values.

Reproduction steps

  1. Submit the form provided in demo application and look to console for output.

Version

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

What browsers are you seeing the problem on?

  • Chrome
  • Firefox
  • Safari
  • Microsoft Edge

When I submit the form in demo link provided, this is the log I get.

Image

As seen, the isDefault attribute is completely missing, unless it is true. Opposed to the enabled attribute which works completely fine.

Demo link

https://stackblitz.com/edit/vitejs-vite-r3tbk5jd?file=src%2FApp.vue

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions