Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions internal/handler/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
* <script src="https://booking.example.com/embed.js" async></script>
* <calnode-booking slug="intro-call"></calnode-booking> <!-- inline -->
* <button data-calnode-popup="intro-call">Book a call</button> <!-- popup -->
*
* Optional identity prefill (#255): when the host page already knows the booker, pass
* name/email and the form opens with those fields filled and read-only.
*
* <calnode-booking slug="intro-call" name="John Doe" email="john@doe.com"></calnode-booking>
*
* Read-only is a convenience, not a guarantee: the booking endpoint still accepts
* whatever a request sends, so this does not prove who booked.
*/
(function () {
'use strict';
Expand Down Expand Up @@ -186,6 +194,9 @@
if (this._mounted) return;
this._mounted = true;
this.slug = this.getAttribute('slug');
// Optional identity prefill (#255). Trimmed; empty means "leave the field editable".
this.prefillName = (this.getAttribute('name') || '').trim();
this.prefillEmail = (this.getAttribute('email') || '').trim();
this.root = this.attachShadow({ mode: 'open' });
var cssLink = el('link', { rel: 'stylesheet', href: BASE + '/booking.css' });
// .clamp styling arrives with the stylesheet, so re-measure the description
Expand Down Expand Up @@ -597,8 +608,15 @@
var form = el('form', { novalidate: 'novalidate' });
var hp = el('input', { type: 'text', name: 'hp_extra', tabindex: '-1', autocomplete: 'off' });
form.appendChild(el('div', { 'aria-hidden': 'true', style: 'position:absolute;left:-5000px;height:0;width:0;overflow:hidden;' }, [hp]));
var name = el('input', { type: 'text', required: 'required', autocomplete: 'name', placeholder: t(this.i18n, 'name_placeholder') });
var email = el('input', { type: 'email', required: 'required', autocomplete: 'email', placeholder: t(this.i18n, 'email_placeholder') });
// Pre-filled and locked when the host page supplied them. `readonly`, not
// `disabled`: the value still submits and the field stays focusable for screen
// readers, which disabled would remove from the tab order.
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);
Comment on lines +614 to +619

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.

form.appendChild(el('div', { class: 'field' }, [el('label', { text: t(this.i18n, 'name_label') }), name]));
form.appendChild(el('div', { class: 'field' }, [el('label', { text: t(this.i18n, 'email_label') }), email]));
var phone = el('input', { type: 'tel', maxlength: '40', autocomplete: 'tel', id: 'phone-call-number' });
Expand Down
25 changes: 25 additions & 0 deletions internal/handler/embed_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,28 @@ func TestBookingCSS_controlsInheritFontFamily(t *testing.T) {
t.Error("booking.css no longer makes form controls inherit font-family; buttons fall back to the UA font inside the embed widget")
}
}

// #255: the host page can pass name/email so the booking form arrives pre-filled and
// read-only. This is a source-level guard: the widget is a web component with no test
// harness here, so what is pinned is that the attributes are still read and still
// render as `readonly` (not `disabled`, which would drop the field from the tab order).
func TestEmbedJS_identityPrefill(t *testing.T) {
h := &Handler{}
rec := httptest.NewRecorder()
h.EmbedJS(rec, httptest.NewRequest(http.MethodGet, "/embed.js", nil))
body := rec.Body.String()

for _, want := range []string{
`this.getAttribute('name')`,
`this.getAttribute('email')`,
`nameAttrs.readonly = 'readonly'`,
`emailAttrs.readonly = 'readonly'`,
} {
if !strings.Contains(body, want) {
t.Errorf("embed.js no longer contains %q - identity prefill may have regressed", want)
}
}
if strings.Contains(body, `disabled = 'disabled'`) {
t.Error("identity fields use disabled, which removes them from the tab order; use readonly")
}
}
Loading