Skip to content

Dot notation data props - #218

Merged
grantcopley merged 4 commits into
coldbox-modules:nextfrom
mrigsby:Dot-Notation-Data-Props
Oct 13, 2025
Merged

Dot notation data props#218
grantcopley merged 4 commits into
coldbox-modules:nextfrom
mrigsby:Dot-Notation-Data-Props

Conversation

@mrigsby

@mrigsby mrigsby commented Oct 12, 2025

Copy link
Copy Markdown
Contributor

Livewire.js already supports dot notation for data properties on the client. This adds server functionality to handle those dot notation keys in your wire.

For Example:

YourWire.cfc Data properties

data = {
    "user": {
        "name": {
            "first": "John",
            "last": "Doe"
        }
    }
};

YourWire.cfm inputs with wire:model

<input type="text"  wire:model="user.name.first">
<input type="text"  wire:model="user.name.last">

Changes/Additions

changes to _applyUpdates( updates ) function ( models/Component.cfc )
  • Uses native structGet() to retrieve values from data properties since it already supports got notation
  • Uses new _updateDataValue() function to update data property values

Note for OnUdpate[ Property ] LifeCycle Events:

Creates onUpdate[ Property ] lifecycle events for nested keys by changing dots to underscores, thus the onUpdate[ Property ] lifecycle event for user.name.first would be onUpdateuser_name_first( newValue, oldValue )

Added _updateDataValue( keyPath, value ) function ( models/Component.cfc )
  • takes two arguments keyPath & value
  • handles dot notation keys (i.e. user.address.zip) and single depth keys (i.e. roles)
  • converts keyPath argument into an array (if not dot notation it is a single value array) and loops over the array of keys to traverse the data properties to get to the target data property and sets the value to the provided value argument
  • Will create keys if they do not exists

TestBox Tests

Adds three tests for functionality. As a note, all other tests are now also using structGet() for retrieval of data properties and _updateDataValue( keyPath, value ) for setting data properties.

  • should provide updates to data properties using dot notation
  • should support incoming array values in dot notation referenced array
  • should call onUpdate[Property_Dot_Notation] if it exists

Added Example

Adds an example wire in the Workshop examples used for the ITB 2024 workshop found at http://127.0.0.1:60299/workshop when the test-harness servers are run. This example uses multiple nested data property keys as well as a nested array for checkboxes.

Other Minor Changes

.gitignore
  • Added views/tmp/** since the test harness created a handful of temporary view files it wanted to include in the commits
  • Added .DS_Store since I work on a mac and it wanted to include all these auto created on my mac

Server .json files Updates for ACF

  • Added a server-adobe@2025.json file for testing on ACF 2025
  • The test-harness server, when running ACF needs the zip package and errors until installed. I added the CFPM entry to install this on startup

@grantcopley
grantcopley requested a review from Copilot October 13, 2025 05:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds server-side support for dot notation data properties in Livewire components, enabling developers to use nested property references like user.name.first in wire:model attributes. The implementation leverages CFML's native structGet() function for retrieving nested values and introduces a new _updateDataValue() function for setting nested property values.

Key changes include:

  • Enhanced _applyUpdates() function to handle dot notation property updates
  • New _updateDataValue() helper function for safely setting nested property values
  • Updated lifecycle event naming for nested properties (dots converted to underscores)

Reviewed Changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
models/Component.cfc Core implementation of dot notation support with new helper function
test-harness/tests/specs/CBWIRESpec.cfc Three new test cases validating dot notation functionality
test-harness/wires/workshop/NestedDataKeys.* Example workshop component demonstrating nested data usage
test-harness/server-adobe@*.json Server configuration updates for ACF compatibility
test-harness/layouts/workshop.cfm Navigation link added for new example

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread models/Component.cfc
Comment thread models/Component.cfc Outdated
@grantcopley grantcopley added this to the v5.0 milestone Oct 13, 2025
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

@grantcopley grantcopley left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrigsby I've pulled this down and tested it and everything seems to be working well. Fantastic work! Merging.

Comment thread models/Component.cfc
@grantcopley
grantcopley merged commit bb5d0fe into coldbox-modules:next Oct 13, 2025
1 check passed
@mrigsby
mrigsby deleted the Dot-Notation-Data-Props branch October 23, 2025 23:35
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.

3 participants