Skip to content

Conversation

@iamgerwin
Copy link
Owner

Summary

Fixed the issue where dependent field values inside Flexible layouts were not being saved when the form was submitted.

Root Cause

  1. The template was missing ref attributes on child components
  2. The fill() method tried to access this.$refs['field-...'] but refs weren't set
  3. In Vue 3, refs created in v-for loops are stored as arrays, not single elements

Solution

Template Changes

<component
  v-for="(field, index) in field.fields"
  :key="field.attribute || index"
  :ref="'field-' + field.attribute"
  ...
/>

fill() Method Changes

let fieldComponent = this.$refs[refKey];

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

Files Changed

File Changes
resources/js/components/FormField.vue Added ref attribute, fixed fill method
dist/js/field.js Rebuilt assets

Fixes #4

- 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
@iamgerwin iamgerwin merged commit 91a4b6e into main Nov 25, 2025
0 of 2 checks passed
@iamgerwin iamgerwin deleted the fix/issue-4-fill-form-data branch November 25, 2025 04:31
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

2 participants