Skip to content

withFieldGroup field path mapping for object mappings creates wrong paths #1645

@MGRatEJOT

Description

@MGRatEJOT

Describe the bug

When we use withFieldGroup and a value of the group/form is an object

const MyGroup = withFieldGroup({
  defaultValues: {
    complexValue: {
      prop1: 0,
      prop2: 0
    }
  },
...
})

and then we use this group somewhere like this, assuming form contains a value "complexValue"

<MyGroup 
  form={form}
  fields={{
    complexValue: "complexValue",
  }}
/>

then the internally created mapping by

getFormFieldName = <TField extends DeepKeys<TFieldGroupData>>(

is wrong, because the combination of the following code line, which keeps a leading dot from the accessor path
e.g. "complexValue.prop1" results in ".prop1" here.

const restOfPath = subfield.slice(firstAccessor.length)

and then later this line

return `${path1}.${path2}`

result in a path with two dots in it.

E.g. "complexValue.prop1" ist getting mapped to "complexValue..prop1"

Your minimal, reproducible example

I have none

Steps to reproduce

I hope my description of the bug and the root cause should be enough information to easily track it down and/or reproduce it.

Expected behavior

Correct mappings should get generated by getFormFieldName.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: Windows
  • Browser: Edge
  • Version: 138.0.3351.95

TanStack Form adapter

None

TanStack Form version

v1.15.0

TypeScript version

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions