Skip to content

Conversation

vonBrax
Copy link
Contributor

@vonBrax vonBrax commented Jul 18, 2025

🔎 Overview

This PR extends the current path syntax to allow for bracket notation.
The reasoning is to allow object keys that contains a "." (dot).
The current syntax only allow bracket notation for root level keys, but not for nested keys.

🤓 Code snippets/examples (if applicable)

const initialValues = {
  'links.twitter': '...',
  'userIds': {
    '123.456': '...'
  }
}

const { defineField } = useForm({initialValues});

defineField('[links.twitter]'); // works

defineField('userIds[123.456]'); // doesn't work

Issues affected

Possibly closes #4762 ?

Discussion

From my perspective, there are 2 possible solutions for this issue (both are not mutually exclusive)

Solution 1 - Extend path syntax

  • Advantage:

    • easier implementation, does not require too many code changes.
  • Disadvantage:

    • requires manual path parsing, might fail for edge cases (I'm including a very basic implementation!)
    • might require external library for proper path parsing?
  • Example implementation (first commit in this PR): 7d3308f

Solution 2 - Accept array as path

  • Advantage:

    • shift the responsibility of providing the correct path to the user, no complex path parsing logic required
    • used for example in the Angular Forms module, in the FormControl get method
  • Disadvantage:

    • Requires code changes in more place
    • Fixes for TS errors
    • Needs serializing logic for path arrays to store path state
  • Implementation: This PR (both solutions are present)

From my understading, this PR does not contain any breaking changes, so could be released as a minor update.
At least, all tests are passing, but maybe I'm missing something?.

Notes

I would be very interested on this solution since I do work with forms that have keys containing dots and they don't work with the current version of this library - not without a patch at least. But at the same time, I understand that this proposed feature has not been fully discussed, so there is a chance that this PR will not be accepted, which would be sad, since I believe this functionality should in one form or another be added. For this reason, I'm creating this PR as a draft.

I'm happy to further discuss the issue and to update the PR if spec modifications are needed.

Copy link

changeset-bot bot commented Jul 18, 2025

⚠️ No Changeset found

Latest commit: 7a3e972

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

netlify bot commented Jul 18, 2025

Deploy Preview for vee-validate-docs canceled.

Name Link
🔨 Latest commit 7a3e972
🔍 Latest deploy log https://app.netlify.com/projects/vee-validate-docs/deploys/687a23e17a5fea0008a0ce73

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

Successfully merging this pull request may close these issues.

Mix of Nested objects and Avoiding nesting

1 participant