oficina / fichas Public

UX fixes from the review: names, 404s, visible links, Email and Phone

Claude Fable 5.1's UX review of Fichas (2026-11-12), its clear defects:
- Every card has a name: an empty or blank title is refused beside the
  field (422) on create and on edit, and a create that leaves the title
  out is asked for it too. "Add a customer" with nothing in it made a
  card called "Card 305".
- Every 404 is the app's error page, chi's unmatched routes included,
  not the router's plain "404 page not found".
- Links read as links: running-text links are faintly underlined;
  "Keep it" on the delete page is the confirm form's Cancel button;
  the fields table's Edit and "Set up its fields first" are buttons.
- Email and Phone are kinds: their own keyboard and autofill, a
  forgiving server check, the email's domain lower-cased, a phone's
  spacing tidied, and mailto:/tel: links on the card (tel: through
  template.URL, digits and + only; neither opens a new tab). The
  shipped Email and Phone fields upgrade from Text on boot
  (kindUpgrades); their prints are unchanged, so duplicates stored
  before still match. Number gets a decimal keypad. Card forms are
  novalidate, so the server's words show, not the browser's.
- Add a field: Email and Phone offered, every kind described; the
  options box only while Choice is picked (CSS :has, no script); the
  duplicate-check tier follows the kind (DefaultTier: Email, Phone and
  Web address findable, the rest private), overridable under Advanced.
- "Fichas", not "fichas", in running copy.

Tests: TestACardNeedsAName, TestNotFoundIsTheAppsOwnPage (both
mutation-checked), TestSeedUpgradesEmailAndPhone,
TestEmailAndPhoneAreCheckedAndTidied, TestANewFieldsTierFollowsItsKind,
TestChoiceOptionsShowOnlyForAChoice (browser).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev e83ebe16de595a9ccc0b4e7a1c2408a7526ebe44 parent 0e2e8fd
26 files changed, +423 −50
  • internal/fichas/app.go +2 −0
  • internal/fichas/auth.go +1 −1
  • internal/fichas/catalogue.go +13 −2
  • internal/fichas/contract_release.go +5 −5
  • internal/fichas/handlers.go +2 −2
  • internal/fichas/handlers_schema.go +9 −2
  • internal/fichas/kinds_test.go +100 −0
  • internal/fichas/print.go +1 −1
  • internal/fichas/read.go +11 −3
  • internal/fichas/render.go +8 −0
  • internal/fichas/schema.go +30 −1
  • internal/fichas/schema_test.go +1 −1
  • internal/fichas/static/fichas.css +26 −2
  • internal/fichas/store.go +47 −0
  • internal/fichas/store_test.go +9 −8
  • internal/fichas/suite_test.go +7 −0
  • internal/fichas/templates/card_delete.html +3 −3
  • internal/fichas/templates/card_edit.html +1 −1
  • internal/fichas/templates/card_new.html +1 −1
  • internal/fichas/templates/card_show.html +1 −1
  • internal/fichas/templates/field_new.html +22 −12
  • internal/fichas/templates/fields.html +2 −2
  • internal/fichas/templates/index.html +1 −1
  • internal/fichas/templates/partials.html +12 −0
  • internal/fichastest/browser_test.go +22 −1
  • internal/fichastest/uxfixes_test.go +86 −0

CI passed — run details

CI log
=== vet ===
go vet ./...
go vet -tags browser ./internal/fichastest/
=== fmt ===
=== test ===
go test ./...
?   	amadan.net/oficina/fichas/cmd/fichas	[no test files]
ok  	amadan.net/oficina/fichas/internal/fichas	2.081s
?   	amadan.net/oficina/fichas/internal/fichas/icons	[no test files]
ok  	amadan.net/oficina/fichas/internal/fichas/seal	0.014s
ok  	amadan.net/oficina/fichas/internal/fichastest	1.262s
?   	amadan.net/oficina/fichas/scripts/mockups	[no test files]
?   	amadan.net/oficina/fichas/scripts/preview	[no test files]
?   	amadan.net/oficina/fichas/scripts/writeestilo	[no test files]
=== migration-check ===
go tool rastrillo migration check
rastrillo migration check: models and migrations agree
diff --git a/internal/fichas/app.go b/internal/fichas/app.go
index 811dd9f..fa4911f 100644
--- a/internal/fichas/app.go
+++ b/internal/fichas/app.go
@@ -65,6 +65,8 @@ func App(d *db.DB, cfg Config, logger *slog.Logger) (*http.ServeMux, *app, error
// is born covered. Origin-checking, not tokens — nothing to mint
// or forget in a form.
r.Use(csrf.Protect(cfg.Origin))
+ // A path nothing answers is the app's 404 page, not chi's plain text.
+ r.NotFound(notFound)
// Sign-in is outside the session guard, necessarily: it is how a
// session is obtained. beginGuard runs before rastrillo's classifier
diff --git a/internal/fichas/auth.go b/internal/fichas/auth.go
index 3ce2154..60cd66f 100644
--- a/internal/fichas/auth.go
+++ b/internal/fichas/auth.go
@@ -195,7 +195,7 @@ func (a *app) requireSession(next http.Handler) http.Handler {
if !ok || !a.Admit(address) {
// 404, not 403: a route you may not use is a route that
// is not there.
- http.NotFound(w, r)
+ notFound(w, r)
return
}
next.ServeHTTP(w, r)
diff --git a/internal/fichas/catalogue.go b/internal/fichas/catalogue.go
index c302224..0249ed1 100644
--- a/internal/fichas/catalogue.go
+++ b/internal/fichas/catalogue.go
@@ -63,6 +63,11 @@ const (
// a shipped field's kind refuses to boot (Seed) — so isLong also
// treats FieldNotes as long.
KindLongText = "longtext"
+ // KindEmail and KindPhone (UX review, 2026-11-12): an email address and
+ // a phone number, each with its own keyboard, a forgiving check, and a
+ // mailto: or tel: link on the card. Both were Text before.
+ KindEmail = "email"
+ KindPhone = "phone"
)
// FaceLatestCall is the FaceKeys token for "the most recent entry".
@@ -107,8 +112,10 @@ var catalogue = []seedType{
// A web address since 2026-09-30 (kindUpgrades): forgiving about
// the scheme, stored as https://, compared by host.
{Key: FieldDomain, Label: "Domain", Kind: KindURL, Tier: TierPrint},
- {Key: FieldEmail, Label: "Email", Kind: KindText, Tier: TierPrint},
- {Key: FieldPhone, Label: "Phone", Kind: KindText, Tier: TierPrint},
+ // Email and Phone since 2026-11-12 (kindUpgrades); their prints
+ // are the same as Text's were, so a value's print does not move.
+ {Key: FieldEmail, Label: "Email", Kind: KindEmail, Tier: TierPrint},
+ {Key: FieldPhone, Label: "Phone", Kind: KindPhone, Tier: TierPrint},
// Sealed. Stage is low-cardinality, so a print would publish
// its equality classes and frequency analysis would order
@@ -302,6 +309,10 @@ func openOptions(s *seal.Sealer, sealed []byte) ([]string, error) {
// someone edits it.
var kindUpgrades = map[string][2]string{
FieldDomain: {KindText, KindURL},
+ // Every Text value is kept as it was; Email and Phone check new input
+ // only, and a stored value they would refuse is flagged at next edit.
+ FieldEmail: {KindText, KindEmail},
+ FieldPhone: {KindText, KindPhone},
}
// upgradeKind moves a shipped field to a new kind and carries its values
diff --git a/internal/fichas/contract_release.go b/internal/fichas/contract_release.go
index e717030..6ea401a 100644
--- a/internal/fichas/contract_release.go
+++ b/internal/fichas/contract_release.go
@@ -103,14 +103,14 @@ func (a *app) contractPage(w http.ResponseWriter, r *http.Request, p contractRel
func (a *app) contractPrepare(w http.ResponseWriter, r *http.Request) {
flow := r.URL.Query().Get("flow")
if _, e := uuid.Parse(flow); e != nil {
- http.NotFound(w, r)
+ notFound(w, r)
return
}
p := contractReleasePage{Flow: flow, Phase: "choose"}
if id, e := strconv.ParseInt(r.URL.Query().Get("card"), 10, 64); e == nil && id > 0 {
c, e := LoadCard(r.Context(), a.db.G, a.sealer, id)
if e != nil {
- http.NotFound(w, r)
+ notFound(w, r)
return
}
p.Card = &c
@@ -152,14 +152,14 @@ func (a *app) contractReview(w http.ResponseWriter, r *http.Request) {
}
flow := r.PostForm.Get("flow")
if _, e := uuid.Parse(flow); e != nil {
- http.NotFound(w, r)
+ notFound(w, r)
return
}
id, _ := strconv.ParseInt(r.PostForm.Get("card"), 10, 64)
rev, _ := strconv.ParseInt(r.PostForm.Get("revision"), 10, 64)
actor, ok := a.identity(r)
if !ok || !a.Admit(actor) {
- http.NotFound(w, r)
+ notFound(w, r)
return
}
var rel releaseEnvelope
@@ -259,7 +259,7 @@ func validContractFlow(s string) bool { _, e := uuid.Parse(s); return e == nil }
func (a *app) contractPrepareReturning(w http.ResponseWriter, r *http.Request) {
flow := r.URL.Query().Get("flow")
if !validContractFlow(flow) {
- http.NotFound(w, r)
+ notFound(w, r)
return
}
http.SetCookie(w, &http.Cookie{Name: "fichas_contract_return", Value: flow, Path: "/", MaxAge: 1800, HttpOnly: true, Secure: true, SameSite: http.SameSiteLaxMode})
diff --git a/internal/fichas/handlers.go b/internal/fichas/handlers.go
index 3c2c863..48852f2 100644
--- a/internal/fichas/handlers.go
+++ b/internal/fichas/handlers.go
@@ -585,7 +585,7 @@ func formValues(r *http.Request, fields []FieldView) map[string]string {
func pathID(w http.ResponseWriter, r *http.Request) (int64, bool) {
id, err := strconv.ParseInt(chi.URLParam(r, "id"), 10, 64)
if err != nil || id <= 0 {
- http.NotFound(w, r)
+ notFound(w, r)
return 0, false
}
return id, true
@@ -595,7 +595,7 @@ func pathID(w http.ResponseWriter, r *http.Request) (int64, bool) {
// suite's rule that a row you cannot have is a row that is not there.
func (a *app) notFoundOrFail(w http.ResponseWriter, r *http.Request, err error) {
if errors.Is(err, gorm.ErrRecordNotFound) {
- http.NotFound(w, r)
+ notFound(w, r)
return
}
a.fail(w, r, err)
diff --git a/internal/fichas/handlers_schema.go b/internal/fichas/handlers_schema.go
index 371316f..f7df31c 100644
--- a/internal/fichas/handlers_schema.go
+++ b/internal/fichas/handlers_schema.go
@@ -15,6 +15,7 @@ import (
var kindWords = map[string]string{
KindText: "Text", KindLongText: "Long text", KindNumber: "Number",
KindDate: "Date", KindEnum: "Choice", KindRef: "Link", KindURL: "Web address",
+ KindEmail: "Email", KindPhone: "Phone",
}
// FieldRow is one line of a type's fields page.
@@ -64,7 +65,7 @@ func (a *app) newField(w http.ResponseWriter, r *http.Request) {
return
}
a.page(w, r, "field_new", map[string]any{"TypeKey": ti.Key, "Type": ti,
- "Form": map[string]string{"kind": KindText, "tier": string(TierSealed)}})
+ "Form": map[string]string{"kind": KindText, "tier": "auto"}})
}
func (a *app) createField(w http.ResponseWriter, r *http.Request) {
@@ -85,11 +86,17 @@ func (a *app) createField(w http.ResponseWriter, r *http.Request) {
Tier: Tier(r.PostForm.Get("tier")),
Options: strings.Split(r.PostForm.Get("options"), "\n"),
}
+ // "auto" (the default, and what a form without the Advanced choice
+ // sends) is the kind's own tier.
+ formTier := r.PostForm.Get("tier")
+ if formTier == "" || formTier == "auto" {
+ spec.Tier, formTier = DefaultTier(spec.Kind), "auto"
+ }
_, err = AddField(r.Context(), a.db.G, a.sealer, ti.Key, actor, spec)
if fe, ok := IsFormError(err); ok {
a.pageStatus(w, r, http.StatusUnprocessableEntity, "field_new", map[string]any{
"TypeKey": ti.Key, "Type": ti, "Errors": fe,
- "Form": map[string]string{"label": spec.Label, "kind": spec.Kind, "tier": string(spec.Tier), "options": r.PostForm.Get("options")}})
+ "Form": map[string]string{"label": spec.Label, "kind": spec.Kind, "tier": formTier, "options": r.PostForm.Get("options")}})
return
}
if err != nil {
diff --git a/internal/fichas/kinds_test.go b/internal/fichas/kinds_test.go
new file mode 100644
index 0000000..71f49f6
--- /dev/null
+++ b/internal/fichas/kinds_test.go
@@ -0,0 +1,100 @@
+package fichas
+
+import (
+ "fmt"
+ "testing"
+
+ "amadan.net/oficina/fichas/internal/fichas/seal"
+)
+
+// The shipped Email and Phone fields were Text. Seed upgrades both on boot;
+// their values and their prints do not move (a print under Email or Phone
+// is the print Text gave the same value), so duplicate-finding keeps
+// matching what was stored before.
+func TestSeedUpgradesEmailAndPhone(t *testing.T) {
+ g, s := seeded(t)
+ card, err := CreateCard(ctx(), g, s, TypeCustomer, Person(1), map[string]string{FieldName: "Brightwater Labs"})
+ if err != nil {
+ t.Fatal(err)
+ }
+ stored := map[string]string{FieldEmail: "Ana@Brightwater.example", FieldPhone: "+353 1 555 0142"}
+ prints := map[string]string{}
+ for key, value := range stored {
+ var fd FieldDef
+ g.Where("key = ?", key).First(&fd)
+ g.Model(&FieldDef{}).Where("id = ?", fd.ID).Update("kind", KindText)
+ old := fd
+ old.Kind = KindText
+ sealed, _ := s.Seal(seal.PurposeValue, []byte(value))
+ pr, _ := printFor(s, old, value)
+ prints[key] = pr
+ g.Create(&CardValue{CardID: card.ID, FieldDefID: fd.ID, SealedValue: sealed, Print: pr})
+ }
+ if err := Seed(g, s); err != nil {
+ t.Fatalf("Seed refused the declared upgrades: %v", err)
+ }
+ for key, want := range map[string]string{FieldEmail: KindEmail, FieldPhone: KindPhone} {
+ var fd FieldDef
+ g.Where("key = ?", key).First(&fd)
+ if fd.Kind != want {
+ t.Errorf("%s is %s, want %s", key, fd.Kind, want)
+ }
+ var v CardValue
+ g.Where("card_id = ? AND field_def_id = ?", card.ID, fd.ID).First(&v)
+ raw, _ := s.Open(seal.PurposeValue, v.SealedValue)
+ if string(raw) != stored[key] {
+ t.Errorf("%s's stored value moved: %q", key, raw)
+ }
+ if v.Print != prints[key] {
+ t.Errorf("%s's print moved, so duplicates stored before would no longer match", key)
+ }
+ }
+}
+
+// Email and Phone are forgiving but not anything-goes; the domain of an
+// address is stored in lower case, and a phone keeps its spacing tidied.
+func TestEmailAndPhoneAreCheckedAndTidied(t *testing.T) {
+ g, s := seeded(t)
+ for name, v := range map[string]map[string]string{
+ "an address with no @": {FieldEmail: "ana.example.com"},
+ "an address with space": {FieldEmail: "ana @example.com"},
+ "an address, no domain": {FieldEmail: "ana@localhost"},
+ "a phone with letters": {FieldPhone: "call me"},
+ "a phone too short": {FieldPhone: "123"},
+ } {
+ v[FieldName] = "Cnoc Teoranta"
+ fe, ok := IsFormError(func() error { _, err := CreateCard(ctx(), g, s, TypeCustomer, Person(1), v); return err }())
+ if !ok {
+ t.Errorf("%s: accepted", name)
+ continue
+ }
+ for k := range v {
+ if k != FieldName && fe[k] == "" {
+ t.Errorf("%s: no message beside %s", name, k)
+ }
+ }
+ }
+ card, err := CreateCard(ctx(), g, s, TypeCustomer, Person(1), map[string]string{
+ FieldName: "Cnoc Teoranta", FieldEmail: " Ana.Ni@Cnoc.Example ", FieldPhone: "+353 1 555 0100",
+ })
+ if err != nil {
+ t.Fatalf("forgiving values refused: %v", err)
+ }
+ view, err := LoadCard(ctx(), g, s, card.ID)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if got := view.Field(FieldEmail).Value; got != "Ana.Ni@cnoc.example" {
+ t.Errorf("email stored as %q", got)
+ }
+ if got := view.Field(FieldPhone).Value; got != "+353 1 555 0100" {
+ t.Errorf("phone stored as %q", got)
+ }
+ links := map[string]string{}
+ for _, d := range view.DetailItems() {
+ links[d["Label"].(string)] = fmt.Sprint(d["Href"])
+ }
+ if links["Email"] != "mailto:Ana.Ni@cnoc.example" || links["Phone"] != "tel:+35315550100" {
+ t.Errorf("the card does not link them: %v", links)
+ }
+}
diff --git a/internal/fichas/print.go b/internal/fichas/print.go
index dab92fd..c955d39 100644
--- a/internal/fichas/print.go
+++ b/internal/fichas/print.go
@@ -48,7 +48,7 @@ func canonical(kind, v string) string {
return v
case KindURL:
return canonicalURL(v)
- case KindText, KindEnum, KindDate, KindRef:
+ case KindText, KindEnum, KindDate, KindRef, KindEmail, KindPhone:
// Phone numbers arrive as text. Keeping digits and a leading +
// makes "+353 1 555 0100" and "+35315550100" one value; anything
// with a letter in it is left alone, so this cannot mangle a name.
diff --git a/internal/fichas/read.go b/internal/fichas/read.go
index 934b1a3..665cf46 100644
--- a/internal/fichas/read.go
+++ b/internal/fichas/read.go
@@ -3,6 +3,7 @@ package fichas
import (
"context"
"fmt"
+ "html/template"
"sort"
"time"
@@ -383,16 +384,23 @@ func (c CardView) DetailItems() []map[string]any {
if c.IsTitle(f.Def.Key) || isLong(f.Def) {
continue
}
- v, href := f.Value, ""
+ v, external := f.Value, false
+ var href any = ""
switch {
case v == "":
v = "—"
case f.Def.Kind == KindDate:
v = displayDate(v)
case f.Def.Kind == KindURL:
- href, v = safeHref(v), displayURL(v)
+ href, v, external = safeHref(v), displayURL(v), true
+ case f.Def.Kind == KindEmail && looksLikeAnEmail(v):
+ href = "mailto:" + v // html/template allows mailto: and escapes it
+ case f.Def.Kind == KindPhone && looksLikeAPhoneNumber(v):
+ // html/template refuses tel: unless told it is safe. It is: only
+ // digits and a leading + survive stripPhoneFormatting.
+ href = template.URL("tel:" + stripPhoneFormatting(v))
}
- out = append(out, map[string]any{"Label": f.Label, "Value": v, "Href": href})
+ out = append(out, map[string]any{"Label": f.Label, "Value": v, "Href": href, "External": external})
}
return out
}
diff --git a/internal/fichas/render.go b/internal/fichas/render.go
index 4d46efa..14099b0 100644
--- a/internal/fichas/render.go
+++ b/internal/fichas/render.go
@@ -98,6 +98,14 @@ func ErrorPage(w http.ResponseWriter, r *http.Request, status int, ref string) {
render(w, "errors", map[string]any{"Status": status, "Ref": ref, "Theme": themeAttr(r)})
}
+// notFound is the app's 404: the error page, never the router's bare
+// "404 page not found" in plain text (UX review, 2026-11-12). Every
+// "this is not here" in Fichas goes through it, including a row you may
+// not see and a route you may not use.
+func notFound(w http.ResponseWriter, r *http.Request) {
+ ErrorPage(w, r, http.StatusNotFound, "")
+}
+
// themeAttr is <html data-theme>: the person's Appearance choice, "light" or
// "dark", and empty for System, when the page follows the operating
// system. Every page draws it, so the scheme is right in the first paint.
diff --git a/internal/fichas/schema.go b/internal/fichas/schema.go
index dc36bdb..20aa814 100644
--- a/internal/fichas/schema.go
+++ b/internal/fichas/schema.go
@@ -67,7 +67,7 @@ func (e FormError) Error() string {
// userKinds are the kinds the designer offers. KindRef ("link to another
// card") needs a picker and waits; offering it without one would store ids
// typed by hand.
-var userKinds = map[string]bool{KindText: true, KindLongText: true, KindNumber: true, KindDate: true, KindEnum: true, KindURL: true}
+var userKinds = map[string]bool{KindText: true, KindLongText: true, KindNumber: true, KindDate: true, KindEnum: true, KindURL: true, KindEmail: true, KindPhone: true}
func (spec FieldSpec) validate() FormError {
e := FormError{}
@@ -389,6 +389,14 @@ func validateValues(defs map[string]FieldDef, values map[string]string) FormErro
if _, err := normaliseURL(v); err != nil {
e[key] = "Enter a web address, like example.com."
}
+ case KindEmail:
+ if !looksLikeAnEmail(v) {
+ e[key] = "Enter an email address, like ana@example.com."
+ }
+ case KindPhone:
+ if !looksLikeAPhoneNumber(v) {
+ e[key] = "Enter a phone number, like +353 1 555 0100."
+ }
case KindEnum:
// The options are sealed and checked by the caller, which has
// them open; see optionsError.
@@ -443,3 +451,24 @@ func IsFormError(err error) (FormError, bool) {
}
return nil, false
}
+
+// looksLikeAnEmail is a forgiving check: something@something.something,
+// no spaces. Whether the address exists is the mail server's question.
+func looksLikeAnEmail(v string) bool {
+ local, domain, ok := strings.Cut(v, "@")
+ return ok && local != "" && !strings.ContainsAny(v, " \t") &&
+ !strings.Contains(domain, "@") && strings.Contains(strings.Trim(domain, "."), ".")
+}
+
+// DefaultTier is the seal tier a kind gets unless someone chooses
+// otherwise (UX review, 2026-11-12: the designer asked every field an
+// encryption question most people cannot weigh). Values people look for
+// duplicates of, an email, a phone, a web address, are findable by exact
+// match; everything else is private.
+func DefaultTier(kind string) Tier {
+ switch kind {
+ case KindEmail, KindPhone, KindURL:
+ return TierPrint
+ }
+ return TierSealed
+}
diff --git a/internal/fichas/schema_test.go b/internal/fichas/schema_test.go
index f064900..87eac6d 100644
--- a/internal/fichas/schema_test.go
+++ b/internal/fichas/schema_test.go
@@ -179,7 +179,7 @@ func TestValuesAreCheckedByKind(t *testing.T) {
if cards != 0 {
t.Fatalf("%d card(s) written despite invalid values", cards)
}
- if _, err := CreateCard(ctx(), g, s, TypeCustomer, Person(1), map[string]string{num.Key: "1,200", FieldStage: "Won"}); err != nil {
+ if _, err := CreateCard(ctx(), g, s, TypeCustomer, Person(1), map[string]string{FieldName: "Cnoc Teoranta", num.Key: "1,200", FieldStage: "Won"}); err != nil {
t.Fatalf("valid values refused: %v", err)
}
}
diff --git a/internal/fichas/static/fichas.css b/internal/fichas/static/fichas.css
index 8e727f4..33e1c21 100644
--- a/internal/fichas/static/fichas.css
+++ b/internal/fichas/static/fichas.css
@@ -199,8 +199,17 @@
[fichas-appbar-actions] { display: flex; gap: var(--rst-sp-2); }
/* ---- Links in running text: text-coloured, underline on hover. */
-[fichas-link] { color: var(--rst-text); text-decoration: none; }
-[fichas-link]:hover { text-decoration: underline; }
+/* A link in running text: text-coloured (Calma: only icons carry colour)
+ but always underlined, faintly, so it reads as a link before it is
+ hovered (UX review, 2026-11-12: "Keep it" and "Edit" read as prose). */
+[fichas-link] {
+ color: var(--rst-text);
+ text-decoration: underline;
+ text-decoration-color: color-mix(in srgb, var(--rst-text) 30%, transparent);
+ text-decoration-thickness: 1px;
+ text-underline-offset: 0.2em;
+}
+[fichas-link]:hover { text-decoration-color: currentColor; }
/* ---- The record bar sits under the view switch, full width, with room. */
[fichas-toolbar] + [rst-lbar] { margin-block-end: var(--rst-sp-4); }
@@ -405,3 +414,18 @@
border-radius: 14px;
box-shadow: 0 0 0 1px var(--rst-line), 0 12px 28px -18px rgb(23 32 60 / 0.25);
}
+
+/* ---- A number field: figures line up as they are typed. */
+[fichas-number] { font-variant-numeric: tabular-nums; }
+
+/* ---- Add a field: the choices box only while Choice is picked, and the
+ storage question tucked under Advanced (UX review, 2026-11-12). */
+[fichas-form]:has(input[name="kind"]:checked:not([value="enum"])) [fichas-choice-options] { display: none; }
+[fichas-advanced] { margin-block: var(--rst-sp-2) var(--rst-sp-4); }
+[fichas-advanced] > summary {
+ cursor: pointer;
+ color: var(--rst-text-muted);
+ font-size: var(--rst-fs-sm);
+ font-weight: 600;
+ margin-block-end: var(--rst-sp-3);
+}
diff --git a/internal/fichas/store.go b/internal/fichas/store.go
index f51d45e..889970a 100644
--- a/internal/fichas/store.go
+++ b/internal/fichas/store.go
@@ -183,6 +183,14 @@ func writeValues(tx *gorm.DB, s *seal.Sealer, cardID int64, defs map[string]Fiel
switch defs[k].Kind {
case KindNumber:
v = strings.ReplaceAll(strings.TrimSpace(v), ",", "")
+ case KindEmail:
+ // The domain is case-blind; the local part is the server's
+ // business, so it is left as typed.
+ if local, domain, ok := strings.Cut(strings.TrimSpace(v), "@"); ok {
+ v = local + "@" + strings.ToLower(domain)
+ }
+ case KindPhone:
+ v = strings.Join(strings.Fields(v), " ")
case KindURL:
// A value that will not normalise is left as typed so that
// validateValues can say what is wrong with it.
@@ -194,6 +202,18 @@ func writeValues(tx *gorm.DB, s *seal.Sealer, cardID int64, defs map[string]Fiel
}
values = normalised
fe := validateValues(defs, values)
+ // Every card has a name (UX review, 2026-11-12: an empty "Add a
+ // customer" made a card called "Card 305"). The browser's required
+ // attribute is a convenience; this is the rule. A write that does not
+ // touch the title (a partial update) is not asked for it.
+ if title := titleOf(defs); title != "" {
+ if v, ok := values[title]; ok && strings.TrimSpace(v) == "" {
+ if fe == nil {
+ fe = FormError{}
+ }
+ fe[title] = "Give it a name."
+ }
+ }
fe, err := optionsError(s, defs, values, fe)
if err != nil {
return nil, nil, err
@@ -386,6 +406,18 @@ func CreateCard(ctx context.Context, db *gorm.DB, s *seal.Sealer, typeKey string
return err
}
+ // A new card is asked for its name even if the caller left the
+ // title out altogether.
+ if t := titleOf(defs); t != "" {
+ if _, ok := values[t]; !ok {
+ withTitle := make(map[string]string, len(values)+1)
+ for k, v := range values {
+ withTitle[k] = v
+ }
+ withTitle[t] = ""
+ values = withTitle
+ }
+ }
card = Card{CardTypeID: ct.ID, OwnerID: actor.memberID, Revision: nextRevision(0), Nonce: randomPositive()}
if err := tx.Create(&card).Error; err != nil {
return fmt.Errorf("fichas: creating the card: %w", err)
@@ -538,3 +570,18 @@ func AddEntry(ctx context.Context, db *gorm.DB, s *seal.Sealer, cardID int64, ac
}
return entry, nil
}
+
+// titleOf is the field a type's cards are named by: Name where the type
+// has it, otherwise its first field (CardView.titleKey's rule).
+func titleOf(defs map[string]FieldDef) string {
+ if _, ok := defs[FieldName]; ok {
+ return FieldName
+ }
+ first, best := "", 0
+ for k, d := range defs {
+ if first == "" || d.Ordinal < best || (d.Ordinal == best && k < first) {
+ first, best = k, d.Ordinal
+ }
+ }
+ return first
+}
diff --git a/internal/fichas/store_test.go b/internal/fichas/store_test.go
index 81f7908..71fdc8f 100644
--- a/internal/fichas/store_test.go
+++ b/internal/fichas/store_test.go
@@ -93,6 +93,7 @@ func TestCreateCardSealsAndLogs(t *testing.T) {
func TestCreateCardPrintsOnlyPrintedFields(t *testing.T) {
g, s := seeded(t)
card, err := CreateCard(ctx(), g, s, TypeCustomer, Person(1), map[string]string{
+ FieldName: "Cnoc Teoranta",
FieldEmail: "Ana@Example.com", // capitalised on purpose
FieldNotes: "not a printed field",
})
@@ -127,7 +128,7 @@ func TestCreateCardPrintsOnlyPrintedFields(t *testing.T) {
func TestUpdateCardLogsBeforeAndAfter(t *testing.T) {
g, s := seeded(t)
- card, _ := CreateCard(ctx(), g, s, TypeCustomer, Person(1), map[string]string{FieldStage: "Lead"})
+ card, _ := CreateCard(ctx(), g, s, TypeCustomer, Person(1), map[string]string{FieldName: "Cnoc Teoranta", FieldStage: "Lead"})
if err := UpdateCard(ctx(), g, s, card.ID, Person(2), map[string]string{FieldStage: "Proposal"}); err != nil {
t.Fatalf("UpdateCard: %v", err)
@@ -161,9 +162,9 @@ func TestUpdateCardLogsBeforeAndAfter(t *testing.T) {
// stops meaning anything if pressing save counts.
func TestUpdateCardWithNoChangeWritesNoEvent(t *testing.T) {
g, s := seeded(t)
- card, _ := CreateCard(ctx(), g, s, TypeCustomer, Person(1), map[string]string{FieldStage: "Lead"})
+ card, _ := CreateCard(ctx(), g, s, TypeCustomer, Person(1), map[string]string{FieldName: "Cnoc Teoranta", FieldStage: "Lead"})
- if err := UpdateCard(ctx(), g, s, card.ID, Person(1), map[string]string{FieldStage: "Lead"}); err != nil {
+ if err := UpdateCard(ctx(), g, s, card.ID, Person(1), map[string]string{FieldName: "Cnoc Teoranta", FieldStage: "Lead"}); err != nil {
t.Fatalf("UpdateCard: %v", err)
}
if n := len(events(t, g, ObjectCard, card.ID)); n != 1 {
@@ -259,7 +260,7 @@ func TestATypeIsACardsOrAnEntrys(t *testing.T) {
if _, err := CreateCard(ctx(), g, s, TypeCallLog, Person(1), nil); err == nil {
t.Error("a card was created with an entry type")
}
- card, err := CreateCard(ctx(), g, s, TypeCustomer, Person(1), nil)
+ card, err := CreateCard(ctx(), g, s, TypeCustomer, Person(1), map[string]string{FieldName: "Cnoc Teoranta"})
if err != nil {
t.Fatalf("CreateCard: %v", err)
}
@@ -271,14 +272,14 @@ func TestATypeIsACardsOrAnEntrys(t *testing.T) {
// The app-as-itself actor must be asked for, never arrived at by default.
func TestAnActorIsAPersonOrADeclaredAppAction(t *testing.T) {
g, s := seeded(t)
- if _, err := CreateCard(ctx(), g, s, TypeCustomer, Actor{}, nil); err == nil {
+ if _, err := CreateCard(ctx(), g, s, TypeCustomer, Actor{}, map[string]string{FieldName: "Cnoc Teoranta"}); err == nil {
t.Error("a zero Actor was accepted; a handler that forgot the session would write as the app")
}
- if _, err := CreateCard(ctx(), g, s, TypeCustomer, Person(0), nil); err == nil {
+ if _, err := CreateCard(ctx(), g, s, TypeCustomer, Person(0), map[string]string{FieldName: "Cnoc Teoranta"}); err == nil {
t.Error("member 0 was accepted as a person")
}
- card, err := CreateCard(ctx(), g, s, TypeCustomer, AppBecause(0, "intake form"), nil)
+ card, err := CreateCard(ctx(), g, s, TypeCustomer, AppBecause(0, "intake form"), map[string]string{FieldName: "Cnoc Teoranta"})
if err != nil {
t.Fatalf("an app action with a reason was refused: %v", err)
}
@@ -330,7 +331,7 @@ func TestTheCardsRevisionChainIsUnbroken(t *testing.T) {
// "No UpdateEntry exists" was a convention, not an invariant.
func TestEntriesCannotBeRewrittenOrRemoved(t *testing.T) {
g, s := seeded(t)
- card, _ := CreateCard(ctx(), g, s, TypeCustomer, Person(1), nil)
+ card, _ := CreateCard(ctx(), g, s, TypeCustomer, Person(1), map[string]string{FieldName: "Cnoc Teoranta"})
entry, err := AddEntry(ctx(), g, s, card.ID, Person(1), TypeCallLog, "manual", map[string]string{FieldBody: "as said"})
if err != nil {
t.Fatalf("AddEntry: %v", err)
diff --git a/internal/fichas/suite_test.go b/internal/fichas/suite_test.go
index 6e0d7d9..f852e02 100644
--- a/internal/fichas/suite_test.go
+++ b/internal/fichas/suite_test.go
@@ -63,6 +63,13 @@ func mustCard(t *testing.T, g *gorm.DB, a *app, values map[string]string) Card {
// it, so its nonce — half of its item id — is the stored value.
func mustCardBy(t *testing.T, g *gorm.DB, a *app, actor Actor, values map[string]string) Card {
t.Helper()
+ if _, ok := values[FieldName]; !ok {
+ named := map[string]string{FieldName: "Card"}
+ for k, v := range values {
+ named[k] = v
+ }
+ values = named
+ }
c, err := CreateCard(ctx(), g, a.sealer, TypeCustomer, actor, values)
if err != nil {
t.Fatalf("CreateCard: %v", err)
diff --git a/internal/fichas/templates/card_delete.html b/internal/fichas/templates/card_delete.html
index 755f8f7..39bf280 100644
--- a/internal/fichas/templates/card_delete.html
+++ b/internal/fichas/templates/card_delete.html
@@ -12,7 +12,7 @@
{{template "confirm-form" (dict
"Action" (printf "/cards/%d/delete" $c.Card.ID)
"Label" (printf "Delete this %s" (lower $c.TypeLabel))
- "Danger" true)}}
-
-<p><a fichas-link href="/cards/{{$c.Card.ID}}">Keep it</a></p>
+ "Danger" true
+ "CancelHref" (printf "/cards/%d" $c.Card.ID)
+ "CancelLabel" "Keep it")}}
{{end}}
diff --git a/internal/fichas/templates/card_edit.html b/internal/fichas/templates/card_edit.html
index 62f0e5a..02c4910 100644
--- a/internal/fichas/templates/card_edit.html
+++ b/internal/fichas/templates/card_edit.html
@@ -5,7 +5,7 @@
<h1 fichas-appbar-title>Edit {{$c.Title}} <span>{{$c.TypeLabel}}</span></h1>
</header>
-<form method="post" action="/cards/{{$c.Card.ID}}" fichas-form>
+<form method="post" action="/cards/{{$c.Card.ID}}" fichas-form novalidate>
{{range $f := $c.Fields}}{{template "fichas-input" (dict "F" $f "Error" (errFor $.Errors $f.Def.Key))}}{{end}}
{{template "form-foot" (dict "Submit" "Save changes" "CancelHref" (printf "/cards/%d" $c.Card.ID) "CancelLabel" "Cancel")}}
</form>
diff --git a/internal/fichas/templates/card_new.html b/internal/fichas/templates/card_new.html
index ccda331..5730340 100644
--- a/internal/fichas/templates/card_new.html
+++ b/internal/fichas/templates/card_new.html
@@ -4,7 +4,7 @@
<h1 fichas-appbar-title>Add a {{lower .Type.Label}}</h1>
</header>
-<form method="post" action="/cards" fichas-form>
+<form method="post" action="/cards" fichas-form novalidate>
<input type="hidden" name="type" value="{{.TypeKey}}">
{{range $i, $f := .Fields}}{{template "fichas-input" (dict "F" $f "Error" (errFor $.Errors $f.Def.Key) "Autofocus" (eq $i 0))}}{{end}}
{{template "form-foot" (dict "Submit" (printf "Save this %s" (lower .Type.Label)) "CancelHref" (printf "/t/%s" .TypeKey) "CancelLabel" "Cancel")}}
diff --git a/internal/fichas/templates/card_show.html b/internal/fichas/templates/card_show.html
index e3707ff..da9d59e 100644
--- a/internal/fichas/templates/card_show.html
+++ b/internal/fichas/templates/card_show.html
@@ -34,7 +34,7 @@
{{/* rastrillo's detail-list markup, written out because its partial
has no link slot and a web address should be one. */}}
<dl rst-detail>
- {{range $c.DetailItems}}<dt>{{.Label}}</dt><dd>{{with .Href}}<a fichas-link href="{{.}}" target="_blank" rel="noopener noreferrer">{{end}}{{.Value}}{{if .Href}}</a>{{end}}</dd>
+ {{range $c.DetailItems}}<dt>{{.Label}}</dt><dd>{{if .Href}}<a fichas-link href="{{.Href}}"{{if .External}} target="_blank" rel="noopener noreferrer"{{end}}>{{.Value}}</a>{{else}}{{.Value}}{{end}}</dd>
{{end}}
</dl>
</div>
diff --git a/internal/fichas/templates/field_new.html b/internal/fichas/templates/field_new.html
index 59c59c7..66a49b5 100644
--- a/internal/fichas/templates/field_new.html
+++ b/internal/fichas/templates/field_new.html
@@ -6,19 +6,29 @@
<form method="post" action="/t/{{.TypeKey}}/fields" fichas-form>
{{template "field" (dict "ID" "label" "Name" "label" "Label" "Field name" "Value" (index .Form "label") "Placeholder" "e.g. Contract value" "Required" true "Autofocus" true "Error" (errFor .Errors "label"))}}
{{template "choice-field" (dict "Legend" "What kind of value" "Name" "kind" "Options" (list
- (dict "Value" "text" "Title" "Text" "Desc" "A name, an address, a short note." "Checked" (eq (index .Form "kind") "text"))
- (dict "Value" "longtext" "Title" "Long text" "Desc" "Paragraphs." "Checked" (eq (index .Form "kind") "longtext"))
- (dict "Value" "number" "Title" "Number" "Checked" (eq (index .Form "kind") "number"))
- (dict "Value" "date" "Title" "Date" "Checked" (eq (index .Form "kind") "date"))
- (dict "Value" "url" "Title" "Web address" "Desc" "A website or a link. Type it with or without https://." "Checked" (eq (index .Form "kind") "url"))
- (dict "Value" "enum" "Title" "Choice" "Desc" "One of a list you set — like Stage." "Checked" (eq (index .Form "kind") "enum"))))}}
+ (dict "Value" "text" "Title" "Text" "Desc" "A name, a reference, a short note." "Checked" (eq (index .Form "kind") "text"))
+ (dict "Value" "longtext" "Title" "Long text" "Desc" "Paragraphs: notes, a description." "Checked" (eq (index .Form "kind") "longtext"))
+ (dict "Value" "number" "Title" "Number" "Desc" "An amount or a count; sorts as a number." "Checked" (eq (index .Form "kind") "number"))
+ (dict "Value" "date" "Title" "Date" "Desc" "A day: a deadline, a renewal, a next step." "Checked" (eq (index .Form "kind") "date"))
+ (dict "Value" "enum" "Title" "Choice" "Desc" "One of a list you set — like Stage." "Checked" (eq (index .Form "kind") "enum"))
+ (dict "Value" "email" "Title" "Email" "Desc" "An email address, opened in your mail app." "Checked" (eq (index .Form "kind") "email"))
+ (dict "Value" "phone" "Title" "Phone" "Desc" "A phone number, tappable to call." "Checked" (eq (index .Form "kind") "phone"))
+ (dict "Value" "url" "Title" "Web address" "Desc" "A website or a link, with or without https://." "Checked" (eq (index .Form "kind") "url"))))}}
{{with errFor .Errors "kind"}}<p rst-field-error role="alert">{{.}}</p>{{end}}
- {{template "field-textarea" (dict "Name" "options" "Label" "Options, for a Choice" "Value" (index .Form "options") "Rows" 4 "Hint" "one per line" "Error" (errFor .Errors "options"))}}
- {{template "choice-field" (dict "Legend" "Can fichas check it for duplicates?" "Name" "tier" "Options" (list
- (dict "Value" "sealed" "Title" "No — keep it private" "Desc" "Encrypted, readable only when a card is open. It can still be searched, sorted and grouped inside fichas. Right for almost everything." "Checked" (eq (index .Form "tier") "sealed"))
- (dict "Value" "print" "Title" "Yes — findable by exact match" "Desc" "fichas can spot two cards with the same value without opening them. For emails, phone numbers and domains — never for a short list of options, where the matches would give the values away." "Checked" (eq (index .Form "tier") "print"))))}}
- {{with errFor .Errors "tier"}}<p rst-field-error role="alert">{{.}}</p>{{end}}
- {{template "callout" (dict "Tone" "neutral" "Title" "Kind and this choice can't be changed later" "Body" "Both describe how the values are stored, and changing either would mean re-encrypting every one. The name and a Choice's options can always be edited. Adding a field never touches existing cards.")}}
+ {{/* Only for a Choice: hidden by CSS (:has) while another kind is
+ picked, so it needs no script; a browser without :has shows it. */}}
+ <div fichas-choice-options>
+ {{template "field-textarea" (dict "Name" "options" "Label" "The choices" "Value" (index .Form "options") "Rows" 5 "Hint" "One per line, in the order they go — like Lead, Contacted, Won." "Error" (errFor .Errors "options"))}}
+ </div>
+ <details fichas-advanced{{if errFor .Errors "tier"}} open{{end}}>
+ <summary>Advanced</summary>
+ {{template "choice-field" (dict "Legend" "Checking for duplicates" "Name" "tier" "Options" (list
+ (dict "Value" "auto" "Title" "As the kind suggests" "Desc" "Emails, phone numbers and web addresses can be checked for duplicates; everything else stays private. Right for almost everything." "Checked" (eq (index .Form "tier") "auto"))
+ (dict "Value" "sealed" "Title" "Keep it private" "Desc" "Encrypted, readable only when a card is open. Still searched, sorted and grouped inside Fichas." "Checked" (eq (index .Form "tier") "sealed"))
+ (dict "Value" "print" "Title" "Findable by exact match" "Desc" "Fichas can spot two cards with the same value without opening them. Never for a Choice or long text." "Checked" (eq (index .Form "tier") "print"))))}}
+ {{with errFor .Errors "tier"}}<p rst-field-error role="alert">{{.}}</p>{{end}}
+ </details>
+ <p fichas-meta>A field's kind can't be changed once it's added; its name, and a Choice's options, always can.</p>
{{template "form-foot" (dict "Submit" "Add field" "CancelHref" (printf "/t/%s/fields" .TypeKey) "CancelLabel" "Cancel")}}
</form>
{{end}}
diff --git a/internal/fichas/templates/fields.html b/internal/fichas/templates/fields.html
index a19a52f..6585269 100644
--- a/internal/fichas/templates/fields.html
+++ b/internal/fichas/templates/fields.html
@@ -17,11 +17,11 @@
<td>{{.Label}}{{if .Title}} <span fichas-meta>· the card's title</span>{{end}}</td>
<td>{{.Kind}}{{with .Options}} <span fichas-meta>· {{len .}} options</span>{{end}}</td>
<td>{{if .Findable}}Yes{{else}}<span fichas-empty-cell>No — private</span>{{end}}</td>
- <td><a fichas-link href="/fields/{{.Key}}/edit">Edit</a></td>
+ <td><a rst-btn="sm" href="/fields/{{.Key}}/edit" aria-label="Edit {{.Label}}">{{icon "pencil"}} Edit</a></td>
</tr>
{{end}}
</tbody>
</table>
</div>
-<p fichas-meta>Every value is encrypted. "Findable" fields also keep a fingerprint, so fichas can spot two cards with the same email or phone without opening them.</p>
+<p fichas-meta>Every value is encrypted. "Findable" fields also keep a fingerprint, so Fichas can spot two cards with the same email or phone without opening them.</p>
{{end}}
diff --git a/internal/fichas/templates/index.html b/internal/fichas/templates/index.html
index 11a4d84..54aebed 100644
--- a/internal/fichas/templates/index.html
+++ b/internal/fichas/templates/index.html
@@ -107,6 +107,6 @@
"Body" (printf "Each %s is a card: what you know about one of them, and everything you log against it." (lower .Result.Label))
"ActionHref" (printf "/cards/new?type=%s" .TypeKey)
"ActionLabel" (printf "Add a %s" (lower .Result.Label)))}}
-<p><a fichas-link href="{{.Base}}/fields">Set up its fields first</a></p>
+<p><a rst-btn href="{{.Base}}/fields">{{icon "pencil"}} Set up its fields first</a></p>
{{end}}
{{end}}
diff --git a/internal/fichas/templates/partials.html b/internal/fichas/templates/partials.html
index a31c0dd..5fe9a73 100644
--- a/internal/fichas/templates/partials.html
+++ b/internal/fichas/templates/partials.html
@@ -17,6 +17,18 @@
<div rst-field><label rst-field-label for="{{$f.Def.Key}}">{{$f.Label}}</label>
<input rst-input type="text" inputmode="url" autocomplete="url" autocapitalize="none" autocorrect="off" spellcheck="false" id="{{$f.Def.Key}}" name="{{$f.Def.Key}}"{{with $f.Value}} value="{{displayURL .}}"{{end}} placeholder="example.com"{{if .Autofocus}} autofocus{{end}}{{if .Error}} aria-invalid="true" aria-describedby="{{$f.Def.Key}}-error"{{end}}>
{{if .Error}}<p rst-field-error id="{{$f.Def.Key}}-error" role="alert">{{.Error}}</p>{{end}}</div>
+{{- else if or (eq $f.Def.Kind "email") (eq $f.Def.Kind "phone") (eq $f.Def.Kind "number") -}}
+ {{/* The right keyboard and autofill for each. The card forms are
+ novalidate, so the browser's own check (its words, not ours, and
+ stricter than the server's) never runs; the server's message shows
+ beside the field instead. */}}
+ <div rst-field><label rst-field-label for="{{$f.Def.Key}}">{{$f.Label}}</label>
+ <input rst-input id="{{$f.Def.Key}}" name="{{$f.Def.Key}}"
+ {{- if eq $f.Def.Kind "email"}} type="email" inputmode="email" autocomplete="email" autocapitalize="none" autocorrect="off" spellcheck="false" placeholder="name@example.com"
+ {{- else if eq $f.Def.Kind "phone"}} type="tel" inputmode="tel" autocomplete="tel" placeholder="+353 1 555 0100"
+ {{- else}} type="text" inputmode="decimal" fichas-number{{end}}
+ {{- with $f.Value}} value="{{.}}"{{end}}{{if .Autofocus}} autofocus{{end}}{{if .Error}} aria-invalid="true" aria-describedby="{{$f.Def.Key}}-error"{{end}}>
+ {{if .Error}}<p rst-field-error id="{{$f.Def.Key}}-error" role="alert">{{.Error}}</p>{{end}}</div>
{{- else if isLong $f.Def -}}
{{template "field-textarea" (dict "Name" $f.Def.Key "Label" $f.Label "Value" $f.Value "Rows" 4 "Error" .Error)}}
{{- else -}}
diff --git a/internal/fichastest/browser_test.go b/internal/fichastest/browser_test.go
index d84f4ff..58d33b6 100644
--- a/internal/fichastest/browser_test.go
+++ b/internal/fichastest/browser_test.go
@@ -202,7 +202,7 @@ func TestNoZoomOnTap(t *testing.T) {
{"/", `input[name="q"]`},
{"/cards/1", `textarea`},
{"/cards/1/edit", `input[name="f_name"]`},
- {"/t/t_customer/fields/new", `textarea[name="options"]`},
+ {"/t/t_customer/fields/new", `input[name="label"]`}, // the options box shows only for a Choice
{"/types/new", `input[name="label"]`},
} {
// One card, so the list shows its search bar and there is a card
@@ -410,6 +410,27 @@ func TestRailIconsSitOnTheTextsCentreLine(t *testing.T) {
}
}
+// TestChoiceOptionsShowOnlyForAChoice: the add-field form shows the box
+// for a Choice's options only while Choice is picked, with no script.
+func TestChoiceOptionsShowOnlyForAChoice(t *testing.T) {
+ rig := browserApp(t, nil)
+ var before, after bool
+ const shown = `getComputedStyle(document.querySelector('[fichas-choice-options]')).display !== 'none'`
+ rig.Run(
+ chromedp.Navigate(rig.Origin+"/t/t_customer/fields/new"),
+ chromedp.WaitVisible(`input[name="label"]`),
+ harness.Into(&before, chromedp.Evaluate[bool](shown)),
+ chromedp.Evaluate[chromedp.Void](`document.querySelector('input[name="kind"][value="enum"]').click()`),
+ harness.Into(&after, chromedp.Evaluate[bool](shown)),
+ )
+ if before {
+ t.Error("the options box shows while Text is picked")
+ }
+ if !after {
+ t.Error("the options box does not show once Choice is picked")
+ }
+}
+
// TestPrimaryButtonsAreFilled: a form's primary submit is filled with the
// accent, and a danger submit is not a plain white pill. rst-btn's value
// is a word list ("primary lg"); the depth styles once matched only
diff --git a/internal/fichastest/uxfixes_test.go b/internal/fichastest/uxfixes_test.go
new file mode 100644
index 0000000..6abe04a
--- /dev/null
+++ b/internal/fichastest/uxfixes_test.go
@@ -0,0 +1,86 @@
+package fichastest
+
+import (
+ "net/http"
+ "net/url"
+ "strings"
+ "testing"
+)
+
+// An empty "Add a customer" is refused beside the name, and makes no card
+// (UX review, 2026-11-12: it made one called "Card 305").
+func TestACardNeedsAName(t *testing.T) {
+ h := newApp(t)
+ for _, name := range []string{"", " "} {
+ rec := post(t, h, "/cards", url.Values{"f_name": {name}, "f_email": {"ana@example.com"}})
+ if rec.Code != http.StatusUnprocessableEntity {
+ t.Fatalf("name %q: status %d, want 422", name, rec.Code)
+ }
+ if !strings.Contains(rec.Body.String(), "Give it a name.") {
+ t.Errorf("name %q: the form does not say what is missing", name)
+ }
+ }
+ if body := get(t, h, "/").Body.String(); strings.Contains(body, "fichas-row-link") {
+ t.Error("a nameless card was created")
+ }
+ // Editing a card to an empty name is refused the same way.
+ path := createACustomer(t, h, "Cnoc Teoranta")
+ rec := post(t, h, path, url.Values{"f_name": {""}})
+ if rec.Code != http.StatusUnprocessableEntity || !strings.Contains(rec.Body.String(), "Give it a name.") {
+ t.Errorf("an edit to an empty name: status %d", rec.Code)
+ }
+}
+
+// Anything that is not there is the app's own 404 page, never the
+// router's plain "404 page not found".
+func TestNotFoundIsTheAppsOwnPage(t *testing.T) {
+ h := newApp(t)
+ for _, path := range []string{"/no/such/page", "/cards/999999", "/cards/not-a-number", "/t/t_nosuch"} {
+ rec := get(t, h, path)
+ if rec.Code != http.StatusNotFound {
+ t.Errorf("%s: status %d, want 404", path, rec.Code)
+ continue
+ }
+ body := rec.Body.String()
+ if strings.Contains(body, "404 page not found") || !strings.Contains(body, "<html") {
+ t.Errorf("%s: not the app's error page:\n%.300s", path, body)
+ }
+ }
+}
+
+// A new field's findability follows its kind unless someone chooses under
+// Advanced: Email, Phone and Web address are findable, the rest private.
+func TestANewFieldsTierFollowsItsKind(t *testing.T) {
+ h := newApp(t)
+ base := "/t/t_customer/fields"
+ add := func(label, kind, tier string) {
+ t.Helper()
+ form := url.Values{"label": {label}, "kind": {kind}}
+ if tier != "" {
+ form.Set("tier", tier)
+ }
+ if kind == "enum" {
+ form.Set("options", "Small\nLarge")
+ }
+ if rec := post(t, h, base, form); rec.Code != http.StatusSeeOther {
+ t.Fatalf("add %s: status %d\n%s", label, rec.Code, rec.Body.String())
+ }
+ }
+ add("Billing email", "email", "auto")
+ add("Mobile", "phone", "")
+ add("Seats", "number", "auto")
+ add("Size", "enum", "auto")
+ add("Private email", "email", "sealed")
+ page := get(t, h, base).Body.String()
+ for label, findable := range map[string]bool{"Billing email": true, "Mobile": true, "Seats": false, "Size": false, "Private email": false} {
+ i := strings.Index(page, "<td>"+label)
+ if i < 0 {
+ t.Fatalf("%s is not listed", label)
+ }
+ row := page[i:]
+ row = row[:strings.Index(row, "</tr>")]
+ if got := strings.Contains(row, "<td>Yes</td>"); got != findable {
+ t.Errorf("%s: findable %v, want %v", label, got, findable)
+ }
+ }
+}