Skip to content

feat(embed): prefill and lock the booker's name/email from attributes (#255) - #271

Merged
shockalotti merged 1 commit into
mainfrom
feat/embed-prefill-identity
Nov 23, 2026
Merged

shockalotti merged 1 commit into
mainfrom
feat/embed-prefill-identity

Conversation

@shockalotti

Copy link
Copy Markdown
Contributor

Closes #255. The convenience case, as confirmed in the issue — no signed token, no server change.

What it does

<calnode-booking slug="intro" name="John Doe" email="john@doe.com"></calnode-booking>

When present, the matching field is pre-filled and read-only. Both attributes are optional and independent; absent or empty leaves the field exactly as it is today.

readonly, not disabled — the value still submits and the field stays focusable for screen readers, where disabled would drop it from the tab order.

What it is not

A read-only input is not proof of identity: POST /v1/bookings still accepts whatever name and email a request carries. That is called out in the code comment and the widget's usage docs so nobody later mistakes it for an access control. Real verification needs a server-signed token and is a separate piece of work.

Verified in a real browser

Two widgets on one page, one with the attributes and one without, with the form rendered in each:

Name Email
with attributes John Doe, readonly john@doe.com, readonly
without empty, editable empty, editable

Placeholders, required, and the submit path are unchanged in both.

Test

TestEmbedJS_identityPrefill pins that the widget still reads both attributes and still uses readonly rather than disabled. The widget has no browser harness in this repo — the same limitation noted on #227 — so that source-level guard is the practical one; the visual check above was manual.

go test ./... green.

🤖 Generated with Claude Code

…#255)

The embed widget builds its own form, so a host page that already knows who is
booking had no way to pass that in. Two optional attributes now do:

  <calnode-booking slug="intro" name="John Doe" email="john@doe.com"></calnode-booking>

When present, the matching field is pre-filled and read-only. Both are optional
and independent; absent or empty leaves the field editable exactly as before.

`readonly`, not `disabled`: the value still submits and the field stays focusable
for screen readers, where disabled would drop it from the tab order.

This is a convenience only, and the code says so. The booking endpoint still
accepts whatever name/email a request sends, so a read-only input is not proof of
who booked. Verified with the reporter on #255 that the convenience case is the
whole ask; verified identity would need a server-signed token and is not this.

Verified in a real browser with two widgets on one page, one with the attributes
and one without, form rendered in each:
- with attributes: name "John Doe" readonly, email "john@doe.com" readonly
- without: both empty and editable, placeholders unchanged
- both still required and submitting through the same code path

Test: TestEmbedJS_identityPrefill pins that the attributes are still read and the
fields still use readonly rather than disabled. The widget has no browser harness
in this repo, so that is the practical guard; the visual check above is manual.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues — one inline suggestion, plus a note on which paths the prefill does and doesn't cover.

Approach: sound — read the two optional attributes once at mount and let formView build the inputs from them, so every re-render keeps the prefill; the "convenience, not identity" caveat is correctly documented next to the code that implements it.

Reviewed changes — the widget-side prefill for #255 and its source-level guard:

  • internal/handler/embed.js — connectedCallback reads name/email (trimmed) into prefillName/prefillEmail; formView adds value and readonly='readonly' to the corresponding input when set, independently. Header usage docs record the attributes and the non-guarantee.
  • internal/handler/embed_handler_test.go — TestEmbedJS_identityPrefill pins that both attributes are still read and still render readonly; ran green here.

ℹ️ The prefill only covers the inline form path

Both gaps are scope rather than defects, but they mean a host page that "already knows the booker" does not always get that promise. Popup mode has no channel for identity at all (data-calnode-popup and window.Calnode.openPopup(slug, lang) carry slug and lang only), and when assistant_enabled the "Book by chat" link books through the LLM tool-loop, which asks the visitor for name and email itself — so the same widget can produce a booking whose identity differs from the locked field, with a redundant prompt on top. Worth a sentence in the header docs, or a follow-up if parity is wanted.

Technical details
# Prefill does not reach popup entry or the assistant booking path

## Affected sites
- `internal/handler/embed.js:759-767` — `openPopup(slug, lang)` creates the element and sets only `slug`, `data-modal`, `lang`.
- `internal/handler/embed.js:791-794` — `wirePopups` forwards only `data-calnode-popup` and `lang` from the trigger button.
- `internal/handler/embed.js:418-421` — the assistant POST body is `{ messages, timezone, language }`; no identity is sent.
- `internal/handler/booking_assistant.go:341-355` — the `book` tool schema requires `name` and `email` as LLM-supplied arguments, so the prefill cannot influence it without a server-side change.

## Required outcome
- Either document that `name`/`email` apply to the inline form only, or extend the popup entry point and the assistant request to carry the same values so a prefill-aware host page behaves consistently across both paths.

## Suggested approach (optional)
- Header docs: one line stating the attributes apply to the inline widget's form.
- Popup: read optional `data-calnode-name`/`data-calnode-email` off the trigger, or accept `{name, email}` in `openPopup`.
- Assistant: forward the prefill in the existing POST body and have `runAssistantTool` treat them as authoritative for the `book` call — the larger half, and reasonable to defer.

## Open questions for the human (optional)
- Is popup/assistant parity in scope for #255, or explicitly a follow-up?

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash | 𝕏

Comment thread internal/handler/embed.js
Comment on lines +614 to +619
var nameAttrs = { type: 'text', required: 'required', autocomplete: 'name', placeholder: t(this.i18n, 'name_placeholder') };
if (self.prefillName) { nameAttrs.value = self.prefillName; nameAttrs.readonly = 'readonly'; }
var emailAttrs = { type: 'email', required: 'required', autocomplete: 'email', placeholder: t(this.i18n, 'email_placeholder') };
if (self.prefillEmail) { emailAttrs.value = self.prefillEmail; emailAttrs.readonly = 'readonly'; }
var name = el('input', nameAttrs);
var email = el('input', emailAttrs);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A locked field with no visual difference is the one thing a booker will actually run into here: booking.css has no [readonly] rule anywhere (nor does any other template), and browsers do not restyle read-only inputs, so these render exactly like the editable ones beside them — the visitor taps, types, and nothing happens. A small [readonly] rule in booking.css (muted background/border, cursor: default) is the cheapest fix; that stylesheet is shared by all three surfaces, but this is the only one that ever sets readonly, so nothing else changes.

Technical details
# Read-only prefilled inputs have no visual affordance

## Affected sites
- `internal/handler/embed.js:614-619` — the prefill adds `value` + `readonly` and nothing visual.
- `internal/handler/templates/booking.css:240-249` — `.field input` sets border/background for every state; there is no `:read-only` / `[readonly]` variant (the file has no `readonly` occurrence at all).

## Required outcome
- A booker can tell at a glance that the field came pre-filled and cannot be edited, without clicking it first.

## Suggested approach (optional)
- `booking.css`: `.field input:read-only:not(:disabled) { background: #f9fafb; color: #6b7280; cursor: default; }` — `:read-only` also matches non-editable input types, so prefer the attribute selector if you want it strictly on the prefilled case.

@shockalotti
shockalotti merged commit f1c7506 into main Nov 23, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Pass name and email attribute to calnode-booking component

1 participant