Skip to content

fix: wire up generic onAdd and onRemove event callbacks (issue #160)#447

Merged
kevinchappell merged 1 commit into
mainfrom
fix/issue-160-onadd-event-not-firing
May 16, 2026
Merged

fix: wire up generic onAdd and onRemove event callbacks (issue #160)#447
kevinchappell merged 1 commit into
mainfrom
fix/issue-160-onadd-event-not-firing

Conversation

@kevinchappell
Copy link
Copy Markdown
Collaborator

Problem

The onAdd callback was defined in events.js defaults (line 35) but was never actually invoked. Users who configured onAdd in their events config would never see it fire when components were added to the form builder.

Reported in issue #160 (Nov 2018).

Solution

Wire up onAdd to fire alongside the specific add callbacks (onAddRow, onAddColumn, onAddField) — following the same pattern already used by onUpdate which fires alongside onUpdateStage/Row/Column/Field.

Additionally, added onRemove to defaults and wired it alongside onRemoveRow/Column/Field for symmetry.

Changes

  • src/lib/js/common/events.js:

    • Added onRemove to defaults
    • Added events.opts.onAdd(eventData) calls in the 3 add event listeners
    • Added events.opts.onRemove(eventData) calls in the 3 remove event listeners
  • src/lib/js/common/events.test.js:

    • Added 4 tests for generic onAdd callback (row/column/field + combined)
    • Added 4 tests for generic onRemove callback (row/column/field + combined)

Usage

After this fix, users can use onAdd as originally intended:

events: {
  onAdd: (evt) => {
    // Fires whenever ANY component is added (row, column, or field)
    console.log('Component added:', evt.detail)
  },
  onRemove: (evt) => {
    // Fires whenever ANY component is removed (row, column, or field)
    console.log('Component removed:', evt.detail)
  },
}

Testing

  • All 162 tests pass (154 existing + 8 new)
  • Lint passes (Biome)

The onAdd callback was defined in events.js defaults but never actually
invoked. Users configuring onAdd in their events config would never see
it fire when components were added.

Fix:
- Call events.opts.onAdd() alongside onAddRow/onAddColumn/onAddField
  in their respective event listeners
- Add onRemove to defaults and wire it alongside onRemoveRow/onRemoveColumn/
  onRemoveField for symmetry with onAdd
- Add 8 new unit tests covering generic onAdd and onRemove callbacks

This matches the existing pattern used by onUpdate which fires alongside
onUpdateStage/onUpdateRow/onUpdateColumn/onUpdateField.
Copilot AI review requested due to automatic review settings May 16, 2026 04:36
@kevinchappell kevinchappell mentioned this pull request May 16, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 fixes a long-standing issue where the generic onAdd events configuration callback was defined but never invoked, and adds a symmetric generic onRemove callback that fires alongside the existing component-specific add/remove callbacks.

Changes:

  • Invoke events.opts.onAdd(...) for row/column/field add DOM events, alongside onAddRow/onAddColumn/onAddField.
  • Add onRemove to default event options and invoke it for row/column/field removals, alongside onRemoveRow/onRemoveColumn/onRemoveField.
  • Add test coverage for the new generic onAdd and onRemove callback behavior, including “generic + specific both fire” scenarios.

Reviewed changes

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

File Description
src/lib/js/common/events.js Wires generic onAdd/onRemove callbacks into existing add/remove DOM event listeners and adds onRemove to defaults.
src/lib/js/common/events.test.js Adds tests verifying generic onAdd/onRemove fire for row/column/field and alongside specific callbacks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@kevinchappell kevinchappell merged commit f2e04e8 into main May 16, 2026
3 checks passed
@kevinchappell kevinchappell deleted the fix/issue-160-onadd-event-not-firing branch May 16, 2026 04:40
@kevinchappell
Copy link
Copy Markdown
Collaborator Author

🎉 This PR is included in version 5.0.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants