This document describes how NovaDependencyContainer works with whitecube/nova-flexible-content Flexible fields.
Starting from version 1.0.5, NovaDependencyContainer supports conditional field visibility inside Flexible field layouts. This enables dynamic form behavior within repeatable content blocks.
When fields are placed inside a Flexible layout, their attribute names are automatically prefixed by the Flexible field component. For example:
- A field named
typeinside a Flexible layout becomesoverlay_items__0__type - The index (
0,1,2, etc.) changes based on the layout position
This prefixing caused the original dependency detection to fail because it looked for exact attribute matches.
The package now implements context-aware dependency resolution that:
- Detects when a field is inside a Flexible layout context
- Automatically resolves relative field names to their prefixed equivalents
- Supports multiple Flexible attribute formats (double underscore and bracket notation)
- Falls back to suffix matching for edge cases
Use NovaDependencyContainer inside Flexible layouts exactly as you would elsewhere:
use Iamgerwin\NovaDependencyContainer\NovaDependencyContainer;
use Whitecube\NovaFlexibleContent\Flexible;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Text;
Flexible::make('Overlay Items')
->addLayout('Overlay Item', 'overlay_item', [
Select::make('Type')
->options([
'Default' => 'Default',
'Location' => 'Location',
'Contact Us' => 'Contact Us',
]),
NovaDependencyContainer::make([
Text::make('Recipient Email', 'recipient_email')
->rules('nullable', 'email', 'max:255'),
])->dependsOn('type', 'Contact Us'),
NovaDependencyContainer::make([
Text::make('Location Name', 'location_name'),
Text::make('Address', 'address'),
])->dependsOn('type', 'Location'),
]),When you specify dependsOn('type', 'Contact Us'), the package:
- First attempts an exact match for
type - If not found, detects the Flexible context prefix from sibling fields
- Resolves to the prefixed attribute (e.g.,
overlay_items__0__type) - Checks multiple format variations for compatibility
The package recognizes these Flexible field attribute patterns:
| Format | Example |
|---|---|
| Double underscore | overlay_items__0__type |
| Bracket notation | overlay_items[0][type] |
| Single underscore | overlay_items_0_type |
When a field value changes inside a Flexible layout:
- The change event includes the full prefixed attribute
- The package extracts the base attribute name
- Both the full and base attribute values are cached
- Dependencies are re-evaluated against all matching fields
Dependencies work correctly across multiple instances of the same layout. Each layout group maintains its own context, so changing type in one Overlay Item only affects the dependent fields in that same group.
// Layout instance 0: type = 'Contact Us' -> shows recipient_email
// Layout instance 1: type = 'Location' -> shows location_name, address
// Layout instance 2: type = 'Default' -> hides all dependent fieldsCurrently, dependencies are resolved within the same Flexible group context. Cross-group dependencies (e.g., a field in group 0 depending on a field in group 1) are not supported.
The package supports one level of Flexible field nesting. Deeply nested Flexible fields (Flexible inside Flexible) may not resolve correctly.
Flexible field support works best on form views (create/edit). Detail view support is included but may have limitations depending on how the Flexible content renders field data.
If a dependency isn't working inside a Flexible layout:
- Check the field attribute name: Ensure you're using the simple attribute name (e.g.,
type) not the prefixed version - Verify the field exists: The dependent field must be in the same Flexible layout group
- Check the console: Browser dev tools may show helpful debugging information
If a field remains hidden when it should be visible:
- Try selecting a different option and then back to the triggering value
- Ensure the comparison value matches exactly (including case sensitivity)
The Flexible context is detected by examining (in order of priority):
- Cached context prefix from previous field-changed events
- The container's own
attributeproperty - Child field
attributeproperties (inside the dependency container) - Cached dependent field values
- Parent component structure
The context prefix is cached once detected, improving performance and reliability for subsequent dependency checks.
When a field changes inside a Flexible layout, the event is broadcast globally. The dependency container automatically filters events to only process those from the same Flexible group:
- Events with a prefix matching the container's context are processed
- Events from different Flexible groups (different index) are ignored
- Non-prefixed events are processed normally (for non-Flexible contexts)
This ensures that changing a field in Overlay Item #1 doesn't affect the dependent fields in Overlay Item #2.
// Double underscore format
/^(.+__\d+__)/
// Bracket format
/^(.+\[\d+\]\[)/
// Base attribute extraction (double underscore)
/^.+__\d+__(.+)$/
// Base attribute extraction (bracket)
/^.+\[\d+\]\[(.+)\]$/- 1.0.13: Fixed dependent field values not being saved on form submission
- 1.0.12: Added DOM-based watching for Flexible fields where Nova events don't fire
- 1.0.11: Fixed regex patterns to support nova-flexible-content's random key format
- 1.0.10: Fixed FieldServiceProvider not registering assets with Nova
- 1.0.9: Added debug logging to diagnose Flexible field issues
- 1.0.8: Fixed missing compiled assets in package distribution
- 1.0.7: Fixed multi-group context contamination with 4-method detection approach
- 1.0.6: Improved Flexible field context detection and cross-group event filtering
- 1.0.5: Added Flexible field support (this feature)
- 1.0.4: Nova 4.35.x compatibility fixes
- 1.0.0: Initial release