fix: update parent doc link field when nested Quick Edit Form#1506
Open
the-narwhal wants to merge 1 commit into
Open
fix: update parent doc link field when nested Quick Edit Form#1506the-narwhal wants to merge 1 commit into
the-narwhal wants to merge 1 commit into
Conversation
When a Quick Edit Form (QEF) is opened from within another QEF (e.g. creating an Address while creating a Party), Desk.vue re-keys the QEF component on `schemaName + name`, destroying the parent QEF and the Link component whose `this` reference is captured in the afterSync listener. Vue 3 silently no-ops $emit on unmounted components, so triggerChange never reaches the parent doc's set(), leaving the link field unset (data loss). Fix by capturing parentDoc and fieldname before navigation and calling parentDoc.set(fieldname, doc.name) directly in the afterSync listener. Applies to Link, DynamicLink, and MultiLabelLink controls. Likely fixes frappe#1487 too
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
When creating a new linked record from inside a Quick Edit Form (QEF) — for example, creating an Address while in the middle of creating a Customer on an invoice — the newly-created child record is silently never linked back to the parent.
Likely fixes #1487 too
Steps to reproduce:
Result: The customer is saved without the address. No error is shown; the data is silently dropped.
Root Cause
Link.vue(and its siblingsDynamicLink.vue,MultiLabelLink.vue) use the following pattern inopenNewDoc():openQuickEditpushes a new route whose query changes theschemaNameandnameparameters. InDesk.vuethe QEF component is keyed on exactly those values:When the Address QEF opens, the key changes from
"PartyNew Party 01"to"AddressNew Address 01", which destroys the Party QEF — and with it, theLinkcomponent whosethisis closed over in the listener.When the address is later saved and
afterSyncfires,triggerChangecallsthis.$emit('change', …). Vue 3 returns early from$emitwhen a component is unmounted (instance.isUnmountedguard), so the event never propagates,parentDoc.set()is never called, and theaddressfield on the Party doc is never updated.Fix
Capture
parentDocandfieldnamebefore the navigation destroys the component, then directly callparentDoc.set()in the listener as a guaranteed fallback — regardless of whether the Link component is still alive:Because the parent doc is wrapped in Vue's
reactive(), the recreated QEF instance (which gets the same cached doc object) will reactively reflect the updated field value without any extra wiring.triggerChangeis kept as well so the first-level case (non-nested QEF, where the component is still alive) continues to work exactly as before.Files Changed
src/components/Controls/Link.vueparentDoc/fieldname; add directparentDoc.set()call inafterSynclistenersrc/components/Controls/DynamicLink.vuesrc/components/Controls/MultiLabelLink.vue