Repository: TanStack/form (2025-07-21T17:49:54Z)

Issue:
Numeric field name leading zero is trimmed
### Describe the bug

Using only a numeric field name, such as `01234` results in two entries in the form state.

1. Field key `1234` with the submitted value
2. Field key `01234` with a stale value (if set using defaultValues)

### Your minimal, reproducible example

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

### Steps to reproduce

1. Go to https://stackblitz.com/edit/vitejs-vite-xvedmkzi?file=src%2FApp.tsx
2. Fill out the field
3. Submit

### Expected behavior

Fieldnames are treated as strings even when a numeric value has been used.

### How often does this bug happen?

Every time

### Screenshots or Videos

_No response_

### Platform

- OS: MacOs
- Browser: Firefox/Chrome

### TanStack Form adapter

react-form

### TanStack Form version

1.14.1

### TypeScript version

5.8.3

### Additional context

_No response_


Discussion:

Patch:
diff --git a/packages/form-core/src/utils.ts b/packages/form-core/src/utils.ts
index 99ecaf2a4..26f6ece7c 100644
--- a/packages/form-core/src/utils.ts
+++ b/packages/form-core/src/utils.ts
@@ -171,8 +171,14 @@ export function makePathArray(str: string | Array<string | number>) {
       .replace(reMultipleDots, '.')
       .split('.')
       .map((d) => {
-        if (d.indexOf(intPrefix) === 0) {
-          return parseInt(d.substring(intPrefix.length), 10)
+        if (d.startsWith(intPrefix)) {
+          const numStr = d.substring(intPrefix.length)
+          const num = parseInt(numStr, 10)
+
+          if (String(num) === numStr) {
+            return num
+          }
+          return numStr
         }
         return d
       })


Test patch:
diff --git a/packages/form-core/tests/utils.spec.ts b/packages/form-core/tests/utils.spec.ts
index 27464cac9..45e6a60a9 100644
--- a/packages/form-core/tests/utils.spec.ts
+++ b/packages/form-core/tests/utils.spec.ts
@@ -133,6 +133,16 @@ describe('setBy', () => {
       ],
     ])
   })
+
+  it('should correctly set a value on a key with leading zeros', () => {
+    const initial = { name: 'test' }
+    const result = setBy(initial, '01234', 'some-value')
+
+    expect(result).toHaveProperty('01234')
+    expect(result['01234']).toBe('some-value')
+
+    expect(result).not.toHaveProperty('1234')
+  })
 })
 
 describe('deleteBy', () => {
@@ -223,6 +233,15 @@ describe('makePathArray', () => {
     expect(makePathArray('[2][3].a')).toEqual([2, 3, 'a'])
     expect(makePathArray('[4][5][6].b[7]')).toEqual([4, 5, 6, 'b', 7])
   })
+
+  it('should preserve leading zeros on purely numeric strings', () => {
+    expect(makePathArray('01234')).toEqual(['01234'])
+    expect(makePathArray('007')).toEqual(['007'])
+  })
+
+  it('should still convert non-leading-zero numbers to number types', () => {
+    expect(makePathArray('12345')).toEqual([12345])
+  })
 })
 
 describe('determineFormLevelErrorSourceAndValue', () => {