Skip to content

Commit 91a4b6e

Browse files
authored
fix: Dependent field values not saved on form submission (#4) (#12)
* fix: add ref attribute and fix fill method for form submission - Added :ref="'field-' + field.attribute" to child components in template - Fixed fill() method to handle Vue 3's array-based refs in v-for loops - Improved :key binding to use field.attribute for better component tracking - Added debug logging to fill() method * docs: update changelog and version for v1.0.13
1 parent 7b151cc commit 91a4b6e

5 files changed

Lines changed: 37 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22

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

5+
## [1.0.13] - 2025-11-25
6+
7+
### Fixed
8+
- Fixed dependent field values not being saved on form submission
9+
- Added missing `ref` attribute to child components in template for proper Vue component referencing
10+
- Fixed `fill()` method to handle Vue 3's array-based refs in v-for loops
11+
12+
### Changed
13+
- Updated template to use `:ref="'field-' + field.attribute"` for each child field
14+
- Updated `fill()` method to extract first element when ref is an array (Vue 3 behavior)
15+
- Improved `:key` binding to use `field.attribute` for better component tracking
16+
17+
### Technical
18+
- In Vue 3, refs created in v-for loops are stored as arrays, not single elements
19+
- The fill method now correctly accesses `$refs[refKey][0]` when the ref is an array
20+
521
## [1.0.12] - 2025-11-25
622

723
### Fixed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "iamgerwin/nova-dependency-container",
3-
"version": "1.0.12",
3+
"version": "1.0.13",
44
"description": "A Laravel Nova 4 and 5 field container allowing to depend on other fields values",
55
"keywords": [
66
"laravel",

dist/js/field.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/flexible-field-support.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ This ensures that changing a field in Overlay Item #1 doesn't affect the depende
168168

169169
## Version History
170170

171+
- **1.0.13**: Fixed dependent field values not being saved on form submission
171172
- **1.0.12**: Added DOM-based watching for Flexible fields where Nova events don't fire
172173
- **1.0.11**: Fixed regex patterns to support nova-flexible-content's random key format
173174
- **1.0.10**: Fixed FieldServiceProvider not registering assets with Nova

resources/js/components/FormField.vue

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<div v-show="isVisible" :class="containerClasses">
33
<component
44
v-for="(field, index) in field.fields"
5-
:key="index"
5+
:key="field.attribute || index"
6+
:ref="'field-' + field.attribute"
67
:is="`form-${field.component}`"
78
:resource-name="resourceName"
89
:resource-id="resourceId"
@@ -690,15 +691,30 @@ export default {
690691
},
691692
692693
fill(formData) {
694+
console.log('[NovaDependencyContainer] fill() called, isVisible:', this.isVisible);
695+
693696
if (!this.isVisible) {
697+
console.log('[NovaDependencyContainer] Not visible, skipping fill');
694698
return;
695699
}
696700
697701
if (this.field.fields) {
698702
this.field.fields.forEach(field => {
699-
const fieldComponent = this.$refs[`field-${field.attribute}`];
703+
const refKey = `field-${field.attribute}`;
704+
let fieldComponent = this.$refs[refKey];
705+
706+
// In Vue 3, refs in v-for are stored as arrays
707+
if (Array.isArray(fieldComponent)) {
708+
fieldComponent = fieldComponent[0];
709+
}
710+
711+
console.log('[NovaDependencyContainer] Filling field:', field.attribute, 'component:', fieldComponent);
712+
700713
if (fieldComponent && typeof fieldComponent.fill === 'function') {
701714
fieldComponent.fill(formData);
715+
console.log('[NovaDependencyContainer] Field filled:', field.attribute);
716+
} else {
717+
console.log('[NovaDependencyContainer] Could not fill field:', field.attribute, 'ref not found or no fill method');
702718
}
703719
});
704720
}

0 commit comments

Comments
 (0)