Skip to content

Conversation

@iamgerwin
Copy link
Owner

Summary

  • Fixed dependent field values not being saved when the form is submitted
  • The previous fix in v1.0.13 used dynamic string refs which don't work reliably in Vue 3 v-for loops
  • Switched to Vue 3's function ref pattern for proper child component access

Changes

  • Replaced :ref="'field-' + field.attribute" with :ref="(el) => setFieldRef(field.attribute, el)"
  • Added fieldRefs data property to store child field component references
  • Added setFieldRef() method to properly collect and manage child component refs
  • Updated fill() method to use the new fieldRefs object for accessing child components
  • Added cleanup for fieldRefs in beforeUnmount lifecycle hook

Technical Details

  • Vue 3 requires function refs when using dynamic ref names in v-for loops
  • Dynamic string refs like :ref="'field-' + x" create arrays but are unreliable to access via $refs[key]
  • Function refs :ref="(el) => refs[key] = el" provide direct access to component instances

Test Plan

  • Verify dependent fields show/hide correctly based on dependency values
  • Verify dependent field values are properly saved when form is submitted
  • Verify fields inside Flexible layouts work correctly
  • Build production assets with no errors

- Replace dynamic string refs with function refs for Vue 3 compatibility
- Add fieldRefs data property to store child component references
- Add setFieldRef() method to collect refs from function ref callbacks
- Update fill() method to use fieldRefs object for accessing child components
- Add cleanup for fieldRefs in beforeUnmount lifecycle hook

The previous fix using :ref="'field-' + attribute" didn't work reliably
in Vue 3's v-for loops. Function refs provide direct access to components.
@iamgerwin iamgerwin merged commit 4cc4adc into main Nov 25, 2025
0 of 2 checks passed
@iamgerwin iamgerwin deleted the fix/issue-4-dependent-field-values-not-saving branch November 25, 2025 04:43
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.

2 participants