Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@

All notable changes to `nova-dependency-container` will be documented in this file.

## [1.0.13] - 2025-11-25

### Fixed
- Fixed dependent field values not being saved on form submission
- Added missing `ref` attribute to child components in template for proper Vue component referencing
- Fixed `fill()` method to handle Vue 3's array-based refs in v-for loops

### Changed
- Updated template to use `:ref="'field-' + field.attribute"` for each child field
- Updated `fill()` method to extract first element when ref is an array (Vue 3 behavior)
- Improved `:key` binding to use `field.attribute` for better component tracking

### Technical
- In Vue 3, refs created in v-for loops are stored as arrays, not single elements
- The fill method now correctly accesses `$refs[refKey][0]` when the ref is an array

## [1.0.12] - 2025-11-25

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iamgerwin/nova-dependency-container",
"version": "1.0.12",
"version": "1.0.13",
"description": "A Laravel Nova 4 and 5 field container allowing to depend on other fields values",
"keywords": [
"laravel",
Expand Down
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/flexible-field-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ This ensures that changing a field in Overlay Item #1 doesn't affect the depende

## Version History

- **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
Expand Down
20 changes: 18 additions & 2 deletions resources/js/components/FormField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<div v-show="isVisible" :class="containerClasses">
<component
v-for="(field, index) in field.fields"
:key="index"
:key="field.attribute || index"
:ref="'field-' + field.attribute"
:is="`form-${field.component}`"
:resource-name="resourceName"
:resource-id="resourceId"
Expand Down Expand Up @@ -690,15 +691,30 @@ export default {
},

fill(formData) {
console.log('[NovaDependencyContainer] fill() called, isVisible:', this.isVisible);

if (!this.isVisible) {
console.log('[NovaDependencyContainer] Not visible, skipping fill');
return;
}

if (this.field.fields) {
this.field.fields.forEach(field => {
const fieldComponent = this.$refs[`field-${field.attribute}`];
const refKey = `field-${field.attribute}`;
let fieldComponent = this.$refs[refKey];

// In Vue 3, refs in v-for are stored as arrays
if (Array.isArray(fieldComponent)) {
fieldComponent = fieldComponent[0];
}

console.log('[NovaDependencyContainer] Filling field:', field.attribute, 'component:', fieldComponent);

if (fieldComponent && typeof fieldComponent.fill === 'function') {
fieldComponent.fill(formData);
console.log('[NovaDependencyContainer] Field filled:', field.attribute);
} else {
console.log('[NovaDependencyContainer] Could not fill field:', field.attribute, 'ref not found or no fill method');
}
});
}
Expand Down
Loading