Repository navigation
fix: keep newly added singular embeds across form changes - #155
Merged
Merged
Conversation
A singular embed added with the "+" button disappeared on the next form change when none of its fields rendered a named input, e.g. an embed with only array fields and no values yet. The change params then had no key for the embed, so cast_embed fell back to the record's nil value. Stop skipping the hidden fields inputs_for renders. The _persistent_id keeps a singular embed's key in the params, and embeds with a primary key now send their id, so cast_embed updates existing entries instead of replacing them. skip_hidden only existed to keep these fields from conflicting with the old empty-string removal input, which the drop param has since replaced.
tfwright
force-pushed
the
fix/singular-embed-presence
branch
from
October 15, 2026 19:09
a4566e8 to
0d56f4e
Compare
tfwright
marked this pull request as ready for review
October 15, 2026 19:15
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.
A singular embed added with the "+" button disappeared on the next form change if none of its fields rendered a named input. This happens with an embed whose only fields are arrays with no values yet:
ArrayInputrenders hidden inputs only for existing items. For example, pressing Enter in the array input blurs it, which fires achangeevent, and the section collapses before the item is added.On each
validate,Resource.changerebuilds the changeset from the record plus the form params. A singular embed is cleared when its drop param is present, initialized to%{}when its sort param is present (sent only by the "+" button), and otherwise passed tocast_embed. With no key for the embed in the params,cast_embedleaves the field unchanged, so it falls back to the record'snil.embed_formno longer passesskip_hidden={true}toinputs_for, so the hidden fields Phoenix renders are back:_persistent_idkeeps a singular embed's key in the params, socast_embedkeeps the embed.id.cast_embedthen updates existing entries instead of treating each one as new and replacing it, so ids are preserved across saves.skip_hiddenwas added in a3a12a7. Back then, removing a singular embed sentparams[field] = "", which would have conflicted with nested hidden fields under the same key. The drop param has since replaced that input and is checked first inResource.change, so removal still works.Added an array-only
private_dataembed to the testUserschema, plus a container test. The test adds the embed through its sort param, sends another change without it, and asserts that the embed's array input is still rendered. The test fails without the fix.Also checked in the dev app with temporary schema changes:
settings): editing a field and saving keeps the same id.previous_versionswith a primary key): reordering by drag and drop saves the new order with both ids kept, and removing an entry drops the right one and keeps the other's id.