fix: Prefill data on Repeatable panels #127
Open
+63
−12
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ImportData Repeatable Panel Bug - Investigation & Fix
Problem Statement
When using
importData()
with data containing multiple instances of a repeatable panel:Root Cause & Solution
The bug had three interconnected issues, each requiring a specific fix:
Issue 1: Missing 'items' Notifications (Backend)
Problem:
Form.importData()
→syncDataAndFormModel()
added instances but never sent 'items' notifications.Why: Only
Container.importData()
manually sent notifications after callingsyncDataAndFormModel()
.Impact: DOM never updated because Worker never notified main thread about new instances.
Solution: Make
syncDataAndFormModel()
ALWAYS send notifications when instances are added/removed.Result: Both
Form.importData()
andContainer.importData()
automatically get notifications. SimplifiedContainer.importData()
by removing duplicate notification code.Issue 2: InstanceManager Has No DOM Element (Frontend)
Problem: InstanceManager (ID:
panel
) has no DOM element. Only instances exist:panel[0]
,panel[1]
.Why:
fieldChanged()
tried to find#panel
→ not found → exited before handling 'items' notification.Impact: Even with notifications, new instances never rendered.
Solution: Handle 'items' changes BEFORE checking if field exists. Find repeat-wrapper via first instance.
Result: New instances render correctly. Render promise stored for synchronization with value changes.
Issue 3: Race Condition with Name Updates (Radio/Checkbox)
Problem: Radio/checkbox values set BEFORE names updated, causing interference.
Why:
repeat.js
updates names inrequestAnimationFrame
(async) for radio & checbox groups to have different names (so that their selection does not collide with other instances), but value changes processed immediately before the name property was updated, which meant the old bug of cross selection re-appeared.Impact: Radio buttons with same name are mutually exclusive → selecting one deselects the other → data corruption.
Timeline (Broken):
Note: Doc-based forms don't have this issue (they update names synchronously). Only affects AF-based
importData
.Solution: Wait for pending renders +
requestAnimationFrame
BEFORE processing radio/checkbox values.Timeline (Fixed):
Result: Value changes wait for name updates. Radio buttons in different instances have unique names, preventing interference.
Complete Flow (Fixed)
Expected Results:
radio
,radio-1
)Fix #124
Test URLs: