From f7363e98afa99db971fd276b608de2d1192cd345 Mon Sep 17 00:00:00 2001 From: Christian Galo Date: Wed, 28 Oct 2026 14:18:11 -0500 Subject: [PATCH] Show the grant form's supersession hint only once a marked product is chosen Task 5.10 of #269's change. The Issue grant form showed a yellow alert under its lead whenever its Product select offered a product marked with the warning sign, before anything was chosen, so it read as a standing warning. The sentence now reads "This grant would supersede a tier a subscription pays for; its billing pauses until the grant ends." and is the Product field's one hint line, hidden until the operator chooses a marked product and hidden again when an unmarked one is chosen. A refused submission that chose a marked product renders it shown. The form's message is the lead alone. The forms library gains the mechanism, for any Stacked form: a select declares HintOnChoice with its Hint, options carry ShowsHint, and the field part renders the hint only when an offered option shows it, hidden unless the chosen one does, and named by the select's aria-describedby only while it shows. One external script, hint-on-choice.js, loaded with defer by the operator shell, follows later choices and htmx swaps through data-hint-toggle and data-shows-hint. The invariants refuse HintOnChoice off a Stacked select, without a Hint or with a Notice, and the escape hatch refuses data-hint-toggle. The change's text gains a form-library requirement ("A select's hint can wait for the option that shows it") and modifies form-conventions' "Every control has a label, and its hint and error are described" so a hint is described while it shows. docs/design-system.md describes the mechanism in section 8 and adds the script to the progressive-enhancement table. Tests: TestOrgEnrollmentIssueGrantSupersedeHint (at rest, no marked product, a refused submission with a marked, an unmarked and no product, the message the lead alone), TestOperatorShellLoadsTheHintToggle, TestRenderHintOnChoiceFollowsTheChosenOption, TestInvariantsHintOnChoiceBelongsToAStackedSelectWithItsHint, the escape hatch's and the invariant messages' rows, and TestGrantSupersedeHintWalkthrough, which chooses a marked and then an unmarked product on the demo's Carlos Member organization and checks the hint and aria-describedby both ways. Three organization goldens change only in the message and the Product field. Review: round 1, three majors (the hint supplied per render, bypassing the registry's hint checks; no spec for the library's new contract, with form-conventions saying the opposite; the script's break unreachable while the app serves its embedded copy) and five minors, all fixed; round 2, no major. Breaks: 12 of 12 caught. 8 in code; the script's 4 run as a second list whose preparation rebuilds and restarts the app on the broken tree. Full suite on reset databases: 4843 pass, 14 skip. make screens: Carlos Member's organization, open and refused, at both widths, loses the alert. Hand captures of the form at rest, with a marked product chosen and with an unmarked one chosen after it sit beside the change's screens. --- docs/design-system.md | 12 +- internal/embeds/static/hint-on-choice.js | 49 ++++++++ internal/embeds/templates/operator.html | 1 + .../templates/partials/ui_form_field.html | 7 +- internal/forms/forms.go | 11 ++ internal/forms/invariant_messages_test.go | 2 + internal/forms/invariants.go | 10 +- internal/forms/invariants_test.go | 33 +++++ internal/forms/render.go | 49 ++++++-- internal/forms/render_test.go | 28 +++++ .../forms/testdata/invariant-messages.golden | 6 +- internal/server/operator_enrollment_forms.go | 34 +++--- .../server/operator_enrollment_render_test.go | 113 +++++++++++++++--- .../server/operator_sidebar_render_test.go | 10 ++ .../org_enrollment/rich-history-search.html | 10 +- .../server/testdata/org_enrollment/rich.html | 10 +- .../suspended-subscription.html | 8 +- .../design.md | 2 +- .../proposal.md | 5 +- .../specs/form-conventions/spec.md | 26 ++++ .../specs/form-library/spec.md | 26 ++++ .../tasks.md | 6 +- .../grant_supersede_hint_test.go | 88 ++++++++++++++ 23 files changed, 478 insertions(+), 68 deletions(-) create mode 100644 internal/embeds/static/hint-on-choice.js create mode 100644 openspec/changes/grant-pauses-subscription-billing/specs/form-conventions/spec.md create mode 100644 openspec/changes/grant-pauses-subscription-billing/specs/form-library/spec.md create mode 100644 test/e2e/operator-walkthroughs/grant_supersede_hint_test.go diff --git a/docs/design-system.md b/docs/design-system.md index c2cd2ffb..600c7a07 100644 --- a/docs/design-system.md +++ b/docs/design-system.md @@ -635,6 +635,7 @@ htmx 4 swaps every response except 204/304. The contract: | Operator list controls (search, facets, paging) | Work: native GET `action`/`method` present | True progressive enhancement, kept. | | Operator lookup (`operator.lookup.search`, the `Search` kind, §8) | Work: native `method="get"` `action` | True progressive enhancement, kept: a lookup writes nothing, so it never needed the mutation path (`form-conventions`). | | Timezone offset attachment (`grant-valid-until-tz.js`) | Server falls back to its own zone | Optional enhancement, kept. | +| Hint toggled by a select's choice (`hint-on-choice.js`) | Server renders the hint hidden or shown for the chosen option | Optional enhancement: without it the hint stays as rendered. | | Stripe checkout | `HX-Redirect` handoff requires htmx (see `billing.go`) | Require htmx, recorded in code. | A new form names its category; a different answer needs a recorded decision @@ -916,7 +917,8 @@ always, never inside the `