forms: draw a schema-stated closed set as a picker, and gate on it - #395
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Yaraslaut
force-pushed
the
fix/386-forms-enum-choice
branch
from
September 2, 2026 15:12
50d45f6 to
f615ebf
Compare
) `schemaJson<A>()` describes a `glz::enumerate`d C++ `enum class` completely: glaze emits a `oneOf` of `const` alternatives, each with its own `title`. The shipped Qt/QML renderer read none of it. Root cause, two halves that compound: * `resolveProp` collapsed any `oneOf`/`anyOf` to its first non-null branch. That path was added for the nullable-`$ref` shape (#189), where the branches differ only in *nullability*; applied to a closed set, whose branches differ in *value*, it discarded every alternative but the first and left that one's `const` merged onto the field as though the schema had pinned it. * `fields` then never looked at `const` or `enum` at all -- `isChoice` was set solely by `x-optionsAction` -- so the member fell through to the plain `TextField`, and `fieldJsonLiteral` returned whatever was typed. The submit gate reported `ready` for `role = "Emperor"` and assembled a body for it, which is the opposite of what a client-side gate exists to say. `enumChoices()` now recognises "every branch bar `{"type":"null"}` carries a `const`" as a distinct shape from the nullability one -- one branch without a `const` and the whole property falls back, so #189's shape still collapses to its typed branch. The bare JSON-Schema `enum` keyword is read the same way. The resulting `{label, valueJson}` rows have the same shape a fetched `Choice`'s do, so they feed the combo box `isChoice` already draws, with no options action and no round trip; the enum's combo claims the `field_` objectName from the plain `TextField`, exactly as the boolean's `CheckBox` does. `fieldJsonLiteral` refuses a value outside the set, because here -- unlike a `Choice`, whose option list is a snapshot that may be stale -- membership is decidable on the client. `resetFields` clears a combo by `currentIndex`, since it has no writable `text`. Two shipped rungs were drawing free-text boxes for fully enumerated members today: `pastebin::CreatePaste`'s `visibility`/`editability` and `bookmarks::CreateBookmark`'s `visibility`. `docs/spec/forms/forms.md` gains a "Closed sets" section and loses the claim that glaze does not emit `oneOf` -- which was the stated reason `oneOf` was treated as nullability-only, and was false. `tst_DynamicFormEnumChoice.qml` drives every schema verbatim from `schemaJson<>()` for a shipped action. Reverting this change fails 15 of its 17 cases. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Yaraslaut
force-pushed
the
fix/386-forms-enum-choice
branch
from
September 2, 2026 15:44
f615ebf to
3abd73b
Compare
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.
Closes #386.
schemaJson<A>()describes aglz::enumeratedenum classmember completely — glaze emits a closedoneOfofconstalternatives, each carrying its owntitle— butDynamicFormread none of it. A three-value set drew aTextField, andreadywastrueforrole = "Emperor".Two independent halves
resolvePropdiscarded the alternatives. It collapsed anyoneOf/anyOfto its first non-null branch. That path was added for the nullable-$refshape (#189), where the branches differ only in nullability and collapsing is right. Applied to a closed set, whose branches differ in value, it dropped every alternative but the first — and merged that branch'sconstonto the field as if the schema had pinned the value.fieldsnever looked atconst/enum.isChoicekeyed solely onx-optionsAction, so an enum member fell through to the text field andfieldJsonLiteralreturned whatever was typed.The fix
enumChoices()recognises "every branch bar{"type":"null"}carries aconst" as a closed set — distinct from the nullability shape, where one branch has noconstand the property falls back, so #189's case still collapses as before. The bare JSON-Schemaenumkeyword is read the same way. The set draws with the combo boxChoicealready uses (no options action, no fetch — values and labels are both already in the schema), taking thefield_objectName from the hiddenTextFieldexactly as the boolean'sCheckBoxdoes.fieldJsonLiteralrefuses an out-of-set value, so the gate means what it says, andresetFieldsclears a combo bycurrentIndexbecause it has no writabletext.Two shipped rungs were rendering free-text boxes for fully enumerated members today:
pastebin::CreatePaste'svisibility/editability, andbookmarks::CreateBookmark'svisibility.Spec/code disagreement, resolved in the spec's favour
docs/spec/forms/forms.md:819claimed glaze does not emitoneOf. It does, and that sentence was the stated rationale for treatingoneOfas nullability-only — so it was load-bearing, not cosmetic. The spec gains a "Closed sets" section and loses the false claim.The issue's framing was also slightly too broad: the
oneOf-of-consts shape appears only for an enum declaring aglz::meta/glz::enumerate. That was measured directly from aschemaJson<>()dump and is now reflected in both the spec and the code comments. An enum without aglz::metagets a different, worse treatment — filed separately as #392 rather than folded in here.Verification
src/qt/forms/tests/tst_DynamicFormEnumChoice.qml, 17 cases. Every schema in it is pasted verbatim from a realschemaJson<>()dump (kanbanSetMemberRole, pastebinCreatePaste) rather than hand-written to match the implementation.Non-vacuity, measured —
DynamicForm.qmlreverted to its parent commit and rebuilt, new test left in place:16 of 19 entries fail; the 3 that pass are
initTestCase,cleanupTestCaseand one preservation guard. With the fix, 19/19 pass. One case originally passed against the unfixed code — it readconstoff the field descriptor, which never carried it — so it was rewritten to assert onresolveProp's own output and re-measured. TheresetFieldsguard was reverted alone as well:Uncaught exception: Cannot assign to non-existent property "text".Regressions:
ladder_pastebin_tests769 assertions,ladder_bookmarks_tests837,ladder_kanban_tests1240 — all pass.Not verified: the HTML renderer (
morph::render). This change is confined to the Qt/QML renderer; whether the HTML one has the same gap is untested either way.On the QML suite total: it reports
250 passed, 6 failed. The 6 aremodule "Lightweight.Migrations" is not installed, from_deps/lightweight-src/src/tools/dbtool-gui/tests/qml/— a vendored dependency's own QML tests that the harness scans. They fail identically before this change and are unrelated to it.🤖 Generated with Claude Code