Skip to content

fix: Improved Flexible field context detection v2 (#4)#6

Merged
iamgerwin merged 1 commit into
mainfrom
fix/issue-4-flexible-context-detection-v2
Nov 25, 2025
Merged

fix: Improved Flexible field context detection v2 (#4)#6
iamgerwin merged 1 commit into
mainfrom
fix/issue-4-flexible-context-detection-v2

Conversation

@iamgerwin

Copy link
Copy Markdown
Owner

Summary

This PR addresses the remaining issues with Flexible field support where the dependency container was still not working correctly inside Flexible layouts.

Root Cause

The previous fix had a critical bug: when multiple NovaDependencyContainer instances exist in different Flexible groups, the first field-changed event would set the context for ALL containers, causing cross-group contamination.

Solution

Implemented a multi-method context detection approach:

1. Early Context Detection (at mount time)

  • Check container's own attribute for prefix
  • Check child field attributes for prefix
  • Walk up Vue component tree to find Flexible layout parent
  • Check DOM for input elements with prefixed names

2. Improved Event Handling

  • Only cache base attribute values when the event prefix matches our context
  • Filter events strictly once context is detected
  • Claim context only from events that match our dependency fields

3. Prevents Cross-Group Contamination

  • Each container maintains its own context
  • Events from other Flexible groups are ignored

Files Changed

  • resources/js/components/FormField.vue - Main improvements
  • resources/js/components/DetailField.vue - Same detection improvements

Test Plan

  • Verify dependency works in single Flexible layout
  • Verify changing field in group 0 only affects group 0 dependencies
  • Verify changing field in group 1 only affects group 1 dependencies
  • Verify backward compatibility with non-Flexible fields

Related Issue

Fixes #4

…approach

Key improvements:
- Add detectFlexibleContextOnMount() for early context detection
- Detect context from container attribute, child fields, parent components, and DOM
- Only cache base attribute values when context matches event prefix
- Filter events strictly once context is detected
- Claim context only from relevant events (matching dependency fields)

This fixes cross-group contamination in multi-group Flexible layouts where
the first event would incorrectly set context for all containers.

Fixes #4
@iamgerwin iamgerwin merged commit 2eff994 into main Nov 25, 2025
2 checks passed
@iamgerwin iamgerwin deleted the fix/issue-4-flexible-context-detection-v2 branch November 25, 2025 03:21
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.

NovaDependencyContainer inside Flexible field not showing dependent fields

1 participant