@wix/agent-skills 1.16.0 → 1.16.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/skills/wix-app/SKILL.md +72 -8
- package/skills/wix-app/references/CODE_QUALITY.md +0 -1
- package/skills/wix-app/references/DASHBOARD_MODAL.md +21 -14
- package/skills/wix-app/references/DASHBOARD_PAGE.md +30 -184
- package/skills/wix-app/references/EDITOR_REACT_COMPONENT.md +19 -3
- package/skills/wix-app/references/WIX_PATTERNS_DOCS.md +172 -0
- package/skills/wix-app/references/dashboard-page/WDS_LAYOUT.md +187 -0
- package/skills/wix-app/references/editor-react-component/A11Y-REVIEW.md +12 -7
- package/skills/wix-app/references/editor-react-component/ANIMATED-COMPONENTS.md +31 -2
- package/skills/wix-app/references/editor-react-component/COMPONENT-API.md +6 -1
- package/skills/wix-app/references/editor-react-component/COMPONENT-CONFIGURATION.md +60 -0
- package/skills/wix-app/references/editor-react-component/DIRECTIONALITY.md +6 -6
- package/skills/wix-app/references/editor-react-component/FUNCTION-HANDLERS.md +167 -0
- package/skills/wix-app/references/editor-react-component/REACT-GUIDELINES.md +2 -2
- package/skills/wix-app/references/editor-react-component/SITE-CONTEXT-HOOKS.md +187 -0
- package/skills/wix-app/scripts/scan-a11y-code.cjs +777 -0
- package/skills/wix-app/scripts/scan-a11y-eslint.cjs +201 -0
- package/skills/wix-base44-connector/SKILL.md +185 -0
- package/skills/wix-base44-connector/scripts/utils.js +212 -0
- package/skills/wix-design-system/SKILL.md +19 -15
- package/skills/wix-docs/SKILL.md +75 -1
- package/skills/wix-headless/references/CAPABILITIES.md +16 -3
- package/skills/wix-headless/references/SDK_HANDOFF.md +1 -1
- package/skills/wix-headless/references/SEED.md +1 -1
- package/skills/wix-headless/references/inline-recipes/how-to-code-forms.md +560 -102
- package/skills/wix-headless/references/inline-recipes/setup-forms.md +210 -143
- package/skills/wix-manage/SKILL.md +20 -17
- package/skills/wix-manage/references/accessibility/scan-site-accessibility.md +98 -0
- package/skills/wix-manage/references/analytics/analytics-dashboard-navigation.md +1 -2
- package/skills/wix-manage/references/domains/domain-search-purchase-and-connect.md +2603 -0
- package/skills/wix-manage/references/events/create-wix-event.md +112 -90
- package/skills/wix-manage/references/events/manage-wix-events.md +33 -94
- package/skills/wix-manage/references/sites/create-headless-site.md +1 -0
- package/skills/wix-manage/references/sites/manage-oauth-apps.md +154 -0
- package/skills/wix-manage/references/sites/read-site-context.md +125 -0
- package/skills/wix-manage/references/sites/site-import.md +67 -15
- package/skills/wix-manage/references/stores/create-product-catalog-v3.md +273 -0
- package/skills/wix-replatform/resources/rp-target-wix/lib/wix-writers.js +1 -1
- package/skills/wix-vibe-headless/SKILL.md +2 -1
- package/skills/wix-vibe-headless/install/deploy.cjs +63 -3
- package/skills/wix-vibe-headless/platforms/base44-ecom-light-seed.md +104 -0
- package/skills/wix-vibe-headless/platforms/base44-ecom-light.md +74 -0
- package/skills/wix-vibe-headless/platforms/base44.md +15 -40
- package/skills/wix-vibe-headless/references/blog/INSTRUCTIONS.md +7 -11
- package/skills/wix-vibe-headless/references/blog/seed/SEED.md +1 -1
- package/skills/wix-vibe-headless/references/bookings/INSTRUCTIONS.md +7 -11
- package/skills/wix-vibe-headless/references/bookings/seed/SEED.md +1 -1
- package/skills/wix-vibe-headless/references/cms/INSTRUCTIONS.md +1 -2
- package/skills/wix-vibe-headless/references/events/INSTRUCTIONS.md +7 -12
- package/skills/wix-vibe-headless/references/events/seed/SEED.md +1 -1
- package/skills/wix-vibe-headless/references/members/INSTRUCTIONS.md +7 -11
- package/skills/wix-vibe-headless/references/portfolio/INSTRUCTIONS.md +7 -11
- package/skills/wix-vibe-headless/references/portfolio/seed/SEED.md +1 -1
- package/skills/wix-vibe-headless/references/pricing-plans/INSTRUCTIONS.md +7 -11
- package/skills/wix-vibe-headless/references/pricing-plans/seed/SEED.md +1 -1
- package/skills/wix-vibe-headless/references/restaurants/INSTRUCTIONS.md +7 -11
- package/skills/wix-vibe-headless/references/restaurants/seed/SEED.md +1 -1
- package/skills/wix-vibe-headless/references/shared/app/components/WixManageBanner.jsx +1 -1
- package/skills/wix-vibe-headless/references/shared/app/rest/wix-config.js +5 -3
- package/skills/wix-vibe-headless/references/storefront/INSTRUCTIONS.md +75 -13
- package/skills/wix-vibe-headless/references/storefront/app/components/ProductCard.jsx +29 -86
- package/skills/wix-vibe-headless/references/storefront/app/components/ProductGrid.jsx +3 -8
- package/skills/wix-vibe-headless/references/storefront/app/components/VariantPicker.jsx +78 -105
- package/skills/wix-vibe-headless/references/storefront/app/hooks/useProductCard.js +92 -0
- package/skills/wix-vibe-headless/references/storefront/app/hooks/useVariantOptions.js +76 -0
- package/skills/wix-vibe-headless/references/storefront/seed/SEED.md +1 -1
- package/skills/wix-vibe-headless/references/storefront/seed/seed-store.js +44 -5
- package/skills/wix-app/references/AUTO_PATTERNS_DASHBOARD.md +0 -326
- package/skills/wix-app/references/auto-patterns-dashboard/action-cell.md +0 -115
- package/skills/wix-app/references/auto-patterns-dashboard/app-config-structure.md +0 -264
- package/skills/wix-app/references/auto-patterns-dashboard/app-context.md +0 -37
- package/skills/wix-app/references/auto-patterns-dashboard/bulk-actions.md +0 -86
- package/skills/wix-app/references/auto-patterns-dashboard/collection-page-actions.md +0 -119
- package/skills/wix-app/references/auto-patterns-dashboard/collection-page.md +0 -103
- package/skills/wix-app/references/auto-patterns-dashboard/custom-actions-override.md +0 -76
- package/skills/wix-app/references/auto-patterns-dashboard/custom-columns-override.md +0 -82
- package/skills/wix-app/references/auto-patterns-dashboard/custom-components-override.md +0 -89
- package/skills/wix-app/references/auto-patterns-dashboard/custom-header-override.md +0 -124
- package/skills/wix-app/references/auto-patterns-dashboard/custom-sections-override.md +0 -91
- package/skills/wix-app/references/auto-patterns-dashboard/custom-slots-override.md +0 -71
- package/skills/wix-app/references/auto-patterns-dashboard/entity-page-actions.md +0 -70
- package/skills/wix-app/references/auto-patterns-dashboard/entity-page-view-actions.md +0 -73
- package/skills/wix-app/references/auto-patterns-dashboard/entity-page.md +0 -98
- package/skills/wix-app/references/auto-patterns-dashboard/example-patterns.json +0 -278
- package/skills/wix-app/references/auto-patterns-dashboard/pages-configuration.md +0 -94
- package/skills/wix-app/references/auto-patterns-dashboard/resolved-action.md +0 -43
- package/skills/wix-app/references/auto-patterns-dashboard/sdk-utilities.md +0 -66
- package/skills/wix-app/references/auto-patterns-dashboard/views.md +0 -76
- package/skills/wix-app/scripts/generate-auto-patterns.js +0 -510
- package/skills/wix-manage/references/domains/domain-search-and-purchase.md +0 -437
- package/skills/wix-manage/references/stores/create-product-from-image.md +0 -1031
- package/skills/wix-manage/references/stores/create-product-with-options-catalog-v3.md +0 -623
- package/skills/wix-manage/references/stores/setup-online-store-catalog-v3.md +0 -106
|
@@ -1,41 +1,82 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: "How to Code Forms"
|
|
3
|
-
description: The frontend contract for Wix Forms — reading the live form schema (`@wix/forms` `forms.getForm`/`queryForms`/`listForms`, anonymous visitor, NO `auth.elevate`) to render
|
|
3
|
+
description: The frontend contract for Wix Forms — reading the live form schema (`@wix/forms` `forms.getForm`/`queryForms`/`listForms`, anonymous visitor, NO `auth.elevate`) and projecting its **`formFields[]`** to render inputs schema-driven, then the `submissions.createSubmission(submission, options)` write path, keying the `submissions` map by each field's `target`, why the anonymous visitor can submit with no captcha and no `auth.elevate`, why *submissions* read-back is owner-only, the `_id` result field, and mapping `fieldViolations[].errorPath`/`errorType` back to per-input copy. Specifies the *how* (modules + exact calls + the failure modes the docs omit); which forms to render come from the request.
|
|
4
4
|
---
|
|
5
5
|
**RECIPE**: How to Code a Wix Forms Frontend (`@wix/forms`, Form Submissions v4)
|
|
6
6
|
|
|
7
|
-
A concise contract for writing the **frontend code** that renders a seeded form and submits it:
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
A concise contract for writing the **frontend code** that renders a seeded form and submits it:
|
|
8
|
+
**reading the live schema to build the inputs**, collecting the values, and creating a submission.
|
|
9
|
+
**This recipe is the *how* (which modules, which calls), not the *what*** — which forms to render,
|
|
10
|
+
how the page looks, and the framework are decided by the request you're fulfilling.
|
|
11
|
+
|
|
12
|
+
> **This recipe is for CODING the frontend, not for seeding it.** It assumes the form schema already
|
|
13
|
+
> exists (created by `setup-forms.md`) — you have each form's `formId` (and its field `target`s)
|
|
14
|
+
> from the seed's `seeded.forms` map. **The field set, order, labels, `required`, validation format,
|
|
15
|
+
> and dropdown options are read live from the schema at render time** (see "Rendering" below). It
|
|
16
|
+
> says nothing about creating forms — only how to read, render, and submit them from frontend code.
|
|
17
|
+
|
|
18
|
+
> **Render schema-driven by default — read the schema and generate the inputs.** This is the
|
|
19
|
+
> standard path for **every** forms site and what this section documents: an owner edit in the Wix
|
|
20
|
+
> dashboard reflects on the site with no code change, and the submit map can never desync from the
|
|
21
|
+
> schema. A dropdown, non-trivial validation, or several forms on one site are **not** reasons to
|
|
22
|
+
> hardcode — those are exactly what the schema carries, so hardcoding them is strictly more code and
|
|
23
|
+
> more drift. Each form simply reads its own schema by `formId`.
|
|
12
24
|
>
|
|
13
|
-
> **The ONLY exception is a brief that is explicitly design-led** —
|
|
14
|
-
|
|
15
|
-
>
|
|
25
|
+
> **The ONLY exception is a brief that is explicitly design-led** — the visual design is the whole
|
|
26
|
+
> point, the form is a small fixed part of a hand-crafted layout, and dashboard-editability is
|
|
27
|
+
> explicitly not a goal (e.g. the `inquiry-design` wedding-photographer brief). There you may
|
|
28
|
+
> hardcode `<input name="<target>">`, but **read the actual `target`s from the schema — never guess or
|
|
29
|
+
> derive them from labels**: a key that isn't an exact schema `target` 400s the whole submission.
|
|
30
|
+
|
|
31
|
+
> **⚠️ Reading rule — always append `?apiView=SDK` to every doc link below.** The Wix docs render
|
|
32
|
+
> two views of the same page. The **bare / REST view** shows the wrapped REST body
|
|
33
|
+
> (`{ submission: {…} }`) and an `id` field; the **`?apiView=SDK` view** shows the SDK call
|
|
34
|
+
> (`submissions.createSubmission(submission, options)`) and the normalized **`_id`** field. The SDK
|
|
35
|
+
> is what your frontend calls; reading the REST view leads to the wrong call signature and the
|
|
36
|
+
> `id`-vs-`_id` trap.
|
|
16
37
|
|
|
17
38
|
---
|
|
18
39
|
|
|
19
40
|
## The module and the client (read this first)
|
|
20
41
|
|
|
21
42
|
**⚠️ Two modules of `@wix/forms`, both used from the frontend:**
|
|
22
|
-
- **`forms`** — reads the form **schema** to render fields: `import { forms } from "@wix/forms"`,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
43
|
+
- **`forms`** — reads the form **schema** to render fields: `import { forms } from "@wix/forms"`,
|
|
44
|
+
then `forms.getForm(formId)` / `forms.queryForms(query)` / `forms.listForms(namespace)`.
|
|
45
|
+
- **`submissions`** — writes a submission: `import { submissions } from "@wix/forms"`, then
|
|
46
|
+
`submissions.createSubmission(submission, options)`.
|
|
47
|
+
|
|
48
|
+
(The frontend **reads** schemas and **writes** submissions; it never *creates* schemas — that's the
|
|
49
|
+
seed.)
|
|
50
|
+
|
|
51
|
+
**⚠️ CRITICAL: a plain anonymous visitor token reads the form schema — NO `auth.elevate`, no
|
|
52
|
+
backend, no owner creds.** `forms.getForm(formId)` / `forms.listForms("wix.form_app.form")` return
|
|
53
|
+
**200** with the full schema (all `formFields[]` with `identifier` + `inputOptions.target` + the
|
|
54
|
+
`stringOptions.validation`/`componentType`/options blocks, the `steps` layout, `submitSettings`) on
|
|
55
|
+
the same visitor client that submits. **This contradicts the docs**: the API spec lists every read
|
|
56
|
+
method (`getForm`/`queryForms`/`listForms`/`getFormSummary`) as requiring the owner scope
|
|
57
|
+
`WIX_FORMS.FORM_SCHEMA_READ` ("Manage Submissions"), and every SDK example ships an "(with elevated
|
|
58
|
+
permissions)" variant. **Trust the live 200, not the permission table** — Wix grants implicit
|
|
59
|
+
visitor read for published-site rendering. **Do NOT add `auth.elevate` to the read** — it is
|
|
60
|
+
unnecessary, and a pure SPA/static frontend can't elevate anyway and doesn't need to. Schema-driven
|
|
61
|
+
rendering is therefore **universal — every framework, including a pure static SPA, with no server or
|
|
62
|
+
proxy.**
|
|
63
|
+
|
|
64
|
+
**Submissions read-back stays owner-only.** Only the *schema* read is visitor-accessible. **Reading
|
|
65
|
+
submissions back** (`querySubmissionsByNamespace`, `getSubmission`, `countSubmission`) requires the
|
|
66
|
+
owner permission `WIX_FORMS.SUBMISSION_READ_ANY` and is **not** available to a visitor — don't try
|
|
67
|
+
to list/confirm submissions from the frontend. The submit's resolved promise **is** your success
|
|
68
|
+
signal (show a thank-you); the submission lands in the site owner's dashboard.
|
|
69
|
+
|
|
70
|
+
**Auth / client — framework split (the SAME client both reads the schema and submits — no elevate on
|
|
71
|
+
either):**
|
|
72
|
+
- **Astro (Wix-managed):** authentication is ambient. Call `forms.getForm(...)` /
|
|
73
|
+
`forms.listForms(...)` in the page frontmatter / a server route, and
|
|
74
|
+
`submissions.createSubmission(...)` from a server route (`src/pages/api/*.ts`) or a server action
|
|
75
|
+
— **no `createClient`, no `OAuthStrategy`, no `clientId`, no `auth.elevate`.** (The schema read
|
|
76
|
+
can equally run client-side; server-side in SSR is simplest so the fields are in the initial
|
|
77
|
+
HTML.)
|
|
78
|
+
- **Non-Astro (Vite/React/Vue/static):** build one manual visitor client with **both** modules and
|
|
79
|
+
reuse it — the read runs **client-side**, no server needed:
|
|
39
80
|
```js
|
|
40
81
|
import { createClient, OAuthStrategy } from '@wix/sdk';
|
|
41
82
|
import { forms, submissions } from '@wix/forms';
|
|
@@ -49,105 +90,305 @@ A concise contract for writing the **frontend code** that renders a seeded form
|
|
|
49
90
|
```
|
|
50
91
|
The `clientId` is public, not a secret.
|
|
51
92
|
|
|
52
|
-
**⚠️ CRITICAL: do NOT call `auth.elevate` to submit.** An anonymous visitor **can** create a
|
|
93
|
+
**⚠️ CRITICAL: do NOT call `auth.elevate` to submit.** An anonymous visitor **can** create a
|
|
94
|
+
submission on the plain visitor token (it stamps `submitter.visitorId`). A pure SPA/static frontend
|
|
95
|
+
has **no server and cannot elevate** anyway. (The Velo docs example wraps `createSubmission` in
|
|
96
|
+
`auth.elevate` inside a backend `web.js` — that's the Velo hosted pattern, **not** the headless
|
|
97
|
+
visitor path; ignore it here.)
|
|
53
98
|
|
|
54
99
|
---
|
|
55
100
|
|
|
56
101
|
## The features (build the ones the site needs)
|
|
57
102
|
|
|
58
|
-
A forms frontend is essentially one feature — **render the fields, then submit** — plus the
|
|
103
|
+
A forms frontend is essentially one feature — **render the fields, then submit** — plus the
|
|
104
|
+
render/validation details around it. Implement it once per form the site shows.
|
|
59
105
|
|
|
60
106
|
### Rendering the inputs (read the schema, then bind `name` = `target`)
|
|
61
107
|
|
|
62
|
-
**Read the live schema, project its `
|
|
108
|
+
**Read the live schema, project its `formFields` into a render model, and generate one input per
|
|
109
|
+
field.** The field's **`target`** (at `inputOptions.target` — the immutable lowercase snake_case
|
|
110
|
+
key the seed authored, e.g. `first_name`, `message`) becomes the input's **`name`** —
|
|
111
|
+
it's the contract the submission must use. Because the inputs are generated from the schema, the
|
|
112
|
+
field **set, order, labels, `required`, validation format, length/pattern constraints, and dropdown
|
|
113
|
+
options** all track the dashboard: a field the owner adds/removes/relabels — or a constraint they
|
|
114
|
+
tighten — reflects on the site with no code change.
|
|
63
115
|
|
|
64
|
-
**1 · Fetch the schema** (visitor token, no elevate
|
|
116
|
+
**1 · Fetch the schema** (visitor token, no elevate). Fetch by id when you have it (the handoff
|
|
117
|
+
carries `formId`), else discover by namespace. **Note the return shapes differ:** `getForm` resolves
|
|
118
|
+
to the **`Form` directly**, while `listForms` resolves to **`{ forms }`**.
|
|
65
119
|
|
|
66
120
|
```js
|
|
67
121
|
import { forms } from '@wix/forms'; // Astro: call directly. Non-Astro: client.forms
|
|
68
122
|
|
|
69
|
-
|
|
70
|
-
|
|
123
|
+
// ONE form → getForm resolves to the Form directly (not `{ form }`-wrapped)
|
|
124
|
+
const form = await forms.getForm(SEEDED_FORM_ID); // from seeded.forms[].formId
|
|
125
|
+
|
|
126
|
+
// SEVERAL forms on a page → ONE listForms call, not one getForm each.
|
|
127
|
+
// Signature is listForms(namespace, options); `formIds` takes up to 100 ids.
|
|
128
|
+
const { forms: list } = await forms.listForms('wix.form_app.form', { formIds: SEEDED_FORM_IDS });
|
|
129
|
+
|
|
130
|
+
// No ids to hand? Discover every form in the namespace:
|
|
131
|
+
const { forms: all } = await forms.listForms('wix.form_app.form');
|
|
71
132
|
```
|
|
72
133
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
134
|
+
> **`listForms` returns only *enabled* forms by default** — usually what you want on a public site,
|
|
135
|
+
> but it does mean a form the owner disabled silently vanishes from a discovery listing rather than
|
|
136
|
+
> erroring.
|
|
76
137
|
|
|
77
|
-
**Project
|
|
138
|
+
**2 · Project `form.formFields` into a render model.**
|
|
78
139
|
|
|
79
140
|
```js
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
141
|
+
// Display order comes from steps[], not from formFields[] (About Form Fields, "Field order comes
|
|
142
|
+
// from the layout") — including the breakpoint fallback below.
|
|
143
|
+
const order = new Map(
|
|
144
|
+
(form.steps ?? [])
|
|
145
|
+
.flatMap((s) => s.layout?.large?.items ?? s.layout?.medium?.items ?? s.layout?.small?.items ?? [])
|
|
146
|
+
.sort((a, b) => (a.row - b.row) || (a.column - b.column))
|
|
147
|
+
.map((item, i) => [item.fieldId, i]),
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
const camel = (e) => (e ?? '').toLowerCase().replace(/_(.)/g, (_, c) => c.toUpperCase());
|
|
151
|
+
|
|
152
|
+
// The input types THIS renderer handles. BOOLEAN (checkbox), WIX_FILE (file upload / signature),
|
|
153
|
+
// PAYMENT and SCHEDULING need their own controls — a checkbox's label is a Ricos rich-content
|
|
154
|
+
// OBJECT, not a string, so letting one fall through to the text branch prints `[object Object]`
|
|
155
|
+
// (or throws in React). Skip them explicitly; add a branch when a brief needs one.
|
|
156
|
+
// ⚠️ A skipped field that is `required` makes the form UNSUBMITTABLE (the server will demand it), so
|
|
157
|
+
// log that case loudly and write the branch — a consent CHECKBOX is the one you'll hit first.
|
|
158
|
+
const RENDERABLE = new Set(['STRING', 'NUMBER', 'ARRAY', 'ADDRESS']);
|
|
159
|
+
|
|
160
|
+
const inputs = (form.formFields ?? [])
|
|
161
|
+
.filter((f) => f.fieldType === 'INPUT' && !f.hidden // the submit button is fieldType: 'DISPLAY'
|
|
162
|
+
&& RENDERABLE.has(f.inputOptions?.inputType))
|
|
163
|
+
.map((f) => {
|
|
164
|
+
const io = f.inputOptions ?? {};
|
|
165
|
+
// ONE naming rule for BOTH nesting levels (About Form Fields, "How a field is composed"):
|
|
166
|
+
// camelCase the enum value and append `Options` — `inputType` names the outer block,
|
|
167
|
+
// `componentType` the sub-block inside it. DERIVE both; a hardcoded `??` chain of block names
|
|
168
|
+
// silently misses types (TIME_INPUT, DATE_TIME, RATING_INPUT, …) and reads back no label.
|
|
169
|
+
const to = io[`${camel(io.inputType)}Options`] ?? {}; // stringOptions / arrayOptions / …
|
|
170
|
+
const comp = to[`${camel(to.componentType)}Options`] ?? {}; // textInputOptions / dropdownOptions / …
|
|
171
|
+
const val = to.validation ?? {};
|
|
172
|
+
return {
|
|
173
|
+
id: f.id, // used only to order by steps[] below
|
|
174
|
+
target: io.target, // → input `name` (THE submission key)
|
|
175
|
+
inputType: io.inputType,
|
|
176
|
+
label: comp.label ?? io.target,
|
|
177
|
+
placeholder: comp.placeholder ?? '',
|
|
178
|
+
defaultValue: comp.default, // owner-set prefill; undefined → none
|
|
179
|
+
required: io.required ?? false, // NOTE: on inputOptions, not inside validation
|
|
180
|
+
format: val.format, // EMAIL | PHONE | URL | UNKNOWN_FORMAT | …
|
|
181
|
+
minLength: val.minLength, // owner-set length/pattern constraints —
|
|
182
|
+
maxLength: val.maxLength, // carry them so the client validates them too,
|
|
183
|
+
pattern: val.pattern, // not just the server (see "validation" below)
|
|
184
|
+
identifier: f.identifier, // per the field table in About Form Fields
|
|
185
|
+
componentType: to.componentType,
|
|
186
|
+
multiple: io.inputType === 'ARRAY', // multi-choice → submits an ARRAY
|
|
187
|
+
options: comp.options?.map((o) => ({ value: o.value, label: o.label ?? o.value })),
|
|
188
|
+
// PHONE may narrow or preselect the country (both ISO-3166 alpha-2):
|
|
189
|
+
allowedCountryCodes: val.phoneOptions?.allowedCountryCodes,
|
|
190
|
+
defaultCountryCode: comp.defaultCountryCode,
|
|
191
|
+
// ADDRESS fields submit a NESTED OBJECT, not a string. validation.fields lists the subfields
|
|
192
|
+
// and their required-ness; only addressLine2 has a visibility setting, so the filter below
|
|
193
|
+
// hides just that one. `false` for every non-address field.
|
|
194
|
+
addressParts: io.inputType === 'ADDRESS' && Object.entries(val.fields ?? {})
|
|
195
|
+
.filter(([sub]) => comp.fieldSettings?.[sub]?.show !== false)
|
|
196
|
+
.map(([sub, cfg]) => ({ sub, required: cfg?.required ?? false })),
|
|
197
|
+
allowedCountries: val.allowedCountries, // ADDRESS: narrows the country <select>
|
|
198
|
+
};
|
|
199
|
+
})
|
|
200
|
+
// A field the owner never placed in the layout sorts LAST, not first — it still stores values.
|
|
201
|
+
.sort((a, b) => (order.get(a.id) ?? Infinity) - (order.get(b.id) ?? Infinity));
|
|
97
202
|
```
|
|
98
203
|
|
|
99
|
-
|
|
204
|
+
[About Form Fields](https://dev.wix.com/docs/api-reference/crm/forms/form-schemas/about-form-fields)
|
|
205
|
+
documents which `identifier` pairs with which component, which options block each combination nests
|
|
206
|
+
in, and what each field submits — read it rather than guessing a block name. A number, address or
|
|
207
|
+
multi-choice field's `format`/`minLength` come back `undefined`: those constraints exist only on a
|
|
208
|
+
`STRING` field's validation.
|
|
209
|
+
|
|
210
|
+
**⚠️ Two paths the projection gets wrong most often:** `required` is at **`inputOptions.required`**,
|
|
211
|
+
*not* inside the validation block; and unconstrained text reads back as **`UNKNOWN_FORMAT`**, so
|
|
212
|
+
never test for `UNDEFINED`.
|
|
213
|
+
|
|
214
|
+
**3 · Render `inputs.map(...)`**, deriving the control from the projected model — **a dropdown is
|
|
215
|
+
signalled by `componentType`, a textarea by `identifier`, the input `type` by `format`:**
|
|
100
216
|
|
|
101
217
|
```jsx
|
|
102
|
-
|
|
103
|
-
//
|
|
104
|
-
|
|
218
|
+
inputs.map((field) => {
|
|
219
|
+
// Address (MULTILINE_ADDRESS) → a GROUP of sub-inputs; its submission value is an OBJECT.
|
|
220
|
+
// Name each sub-input `${target}/${sub}` — that is EXACTLY the server's error path for a nested
|
|
221
|
+
// field (e.g. "address/subdivision"), so the submit step nests them back AND a per-subfield
|
|
222
|
+
// server error maps straight onto the right control (see "Submitting" and the error mapping below).
|
|
223
|
+
// NB: `country` and `subdivision` are country-dependent enums, not free text (see the ⚠️ note) —
|
|
224
|
+
// render `country` as a <select> (your own, over an ISO-3166 alpha-2 list, narrowed to
|
|
225
|
+
// field.allowedCountries when that's non-empty) rather than a free-text input.
|
|
226
|
+
if (field.addressParts) {
|
|
227
|
+
return (
|
|
228
|
+
<fieldset key={field.target}>
|
|
229
|
+
<legend>{field.label}{field.required && ' *'}</legend>
|
|
230
|
+
{field.addressParts.map(({ sub, required }) => {
|
|
231
|
+
const name = `${field.target}/${sub}`; // == the server errorPath for this subfield
|
|
232
|
+
return (
|
|
233
|
+
<label key={sub}>{sub}{required && ' *'} {/* humanize `sub` for display as you like */}
|
|
234
|
+
{sub === 'country'
|
|
235
|
+
? <CountrySelect name={name} required={required} allowed={field.allowedCountries} />
|
|
236
|
+
: <input name={name} required={required} />}
|
|
237
|
+
{fieldErrors[name] && <small className="field-error">{fieldErrors[name]}</small>}
|
|
238
|
+
</label>
|
|
239
|
+
);
|
|
240
|
+
})}
|
|
241
|
+
</fieldset>
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
// Radio group (single choice) → radios sharing name=target; submits a single string
|
|
245
|
+
if (field.componentType === 'RADIO_GROUP') {
|
|
246
|
+
return (
|
|
247
|
+
<fieldset key={field.target}><legend>{field.label}{field.required && ' *'}</legend>
|
|
248
|
+
{field.options.map((o) => (
|
|
249
|
+
<label key={o.value}><input type="radio" name={field.target} value={o.value}
|
|
250
|
+
defaultChecked={o.value === field.defaultValue} required={field.required} /> {o.label}</label>
|
|
251
|
+
))}
|
|
252
|
+
</fieldset>
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
// Checkbox group (multi choice, inputType ARRAY) → checkboxes sharing name=target; submits an ARRAY
|
|
256
|
+
if (field.multiple) {
|
|
257
|
+
return (
|
|
258
|
+
<fieldset key={field.target}><legend>{field.label}{field.required && ' *'}</legend>
|
|
259
|
+
{field.options.map((o) => (
|
|
260
|
+
<label key={o.value}><input type="checkbox" name={field.target} value={o.value} /> {o.label}</label>
|
|
261
|
+
))}
|
|
262
|
+
</fieldset>
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
// Dropdown → <select> — a single-choice STRING field
|
|
266
|
+
if (field.componentType === 'DROPDOWN') {
|
|
105
267
|
return (
|
|
106
268
|
<label key={field.target}>{field.label}{field.required && ' *'}
|
|
107
|
-
<select name={field.target} required={field.required} defaultValue=
|
|
269
|
+
<select name={field.target} required={field.required} defaultValue={field.defaultValue ?? ''}>
|
|
108
270
|
<option value="" disabled>{field.placeholder || 'Select…'}</option>
|
|
109
271
|
{field.options.map((o) => <option key={o.value} value={o.value}>{o.label}</option>)}
|
|
110
272
|
</select>
|
|
111
273
|
</label>
|
|
112
274
|
);
|
|
113
275
|
}
|
|
114
|
-
// Textarea — detected by
|
|
115
|
-
if (field.
|
|
276
|
+
// Textarea — detected by `identifier` (see gotcha below), NEVER by componentType
|
|
277
|
+
if (field.identifier === 'TEXT_AREA') {
|
|
116
278
|
return (
|
|
117
279
|
<label key={field.target}>{field.label}{field.required && ' *'}
|
|
118
|
-
<textarea name={field.target} required={field.required} rows={4}
|
|
280
|
+
<textarea name={field.target} required={field.required} rows={4} defaultValue={field.defaultValue}
|
|
119
281
|
minLength={field.minLength} maxLength={field.maxLength} />
|
|
120
282
|
</label>
|
|
121
283
|
);
|
|
122
284
|
}
|
|
123
|
-
// Text input — derive `type` from the validation format; stamp the schema's constraints
|
|
285
|
+
// Text/date input — derive `type` from the validation format; stamp the schema's constraints.
|
|
286
|
+
// DATE_INPUT and DATE_PICKER are both format 'DATE' → <input type="date"> (submits a date string).
|
|
124
287
|
const type =
|
|
288
|
+
field.componentType === 'NUMBER_INPUT' ? 'number' : // NUMBER field — no format; empty validation
|
|
125
289
|
field.format === 'EMAIL' ? 'email' :
|
|
126
290
|
field.format === 'PHONE' ? 'tel' :
|
|
127
|
-
field.format === 'URL' ? 'url' :
|
|
291
|
+
field.format === 'URL' ? 'url' :
|
|
292
|
+
field.format === 'DATE' ? 'date' :
|
|
293
|
+
field.format === 'TIME' ? 'time' :
|
|
294
|
+
field.format === 'DATE_TIME' ? 'datetime-local' : 'text';
|
|
295
|
+
// inputMode picks the right on-screen keyboard on mobile; undefined → attribute omitted
|
|
296
|
+
// (date/time use the native picker, so no inputMode).
|
|
297
|
+
const inputMode =
|
|
298
|
+
type === 'number' ? 'decimal' :
|
|
299
|
+
type === 'tel' ? 'tel' :
|
|
300
|
+
type === 'email' ? 'email' :
|
|
301
|
+
type === 'url' ? 'url' : undefined;
|
|
302
|
+
// `defaultValue` is the owner's prefill from the schema — dropping it loses a dashboard setting.
|
|
128
303
|
return (
|
|
129
304
|
<label key={field.target}>{field.label}{field.required && ' *'}
|
|
130
|
-
<input name={field.target} type={type}
|
|
305
|
+
<input name={field.target} type={type} inputMode={inputMode} required={field.required}
|
|
306
|
+
defaultValue={field.defaultValue} placeholder={field.placeholder}
|
|
131
307
|
minLength={field.minLength} maxLength={field.maxLength} pattern={field.pattern} />
|
|
132
308
|
</label>
|
|
133
309
|
);
|
|
134
310
|
});
|
|
135
311
|
```
|
|
136
312
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
313
|
+
**Show the expected shape in the `placeholder`, not a second line of copy.** `format` tells you what
|
|
314
|
+
a constrained field wants, so surface an example up front — but reuse the `placeholder` the render
|
|
315
|
+
already passes rather than adding a separate hint element that just duplicates the inline error. When
|
|
316
|
+
the schema's `placeholder` is empty for a constrained field, synthesize one from `format` (PHONE →
|
|
317
|
+
`phoneExample(field)`, the reserved example for the field's own country — see `PHONE_EXAMPLE` under
|
|
318
|
+
Validation; URL → `https://…`). The example prevents the `must match format "phone"` error
|
|
319
|
+
without a redundant help line under every field.
|
|
320
|
+
|
|
321
|
+
**⚠️ Detection signals — `identifier` and `componentType` are INDEPENDENT axes**, because several
|
|
322
|
+
fields share one general-purpose component
|
|
323
|
+
([About Form Fields](https://dev.wix.com/docs/api-reference/crm/forms/form-schemas/about-form-fields),
|
|
324
|
+
"Some component types serve several fields"). Switch on whichever axis distinguishes the control you
|
|
325
|
+
are rendering — and **never on the `target` name**: a rename silently breaks name-based detection,
|
|
326
|
+
while `identifier` and `componentType` stay authoritative. Three that bite in practice:
|
|
327
|
+
|
|
328
|
+
- **`<textarea>` → `identifier === "TEXT_AREA"`.** `componentType` is `TEXT_INPUT` for short *and*
|
|
329
|
+
long answer, so keying off it renders every long-text field single-line.
|
|
330
|
+
- **`country` / `subdivision` are country-dependent enums the schema does not enumerate**, so a plain
|
|
331
|
+
`<input>` invites a rejection. Render **`country` as a `<select>`** (narrowed to
|
|
332
|
+
`allowedCountries` when non-empty) and, ideally, **`subdivision` as a country-dependent
|
|
333
|
+
`<select>`** from an ISO-3166-2 / Wix subdivision dataset. If you must keep them text, **leave
|
|
334
|
+
`subdivision` optional** and rely on the mapped inline error.
|
|
335
|
+
- **`IMAGE_CHOICE` looks exactly like multi-choice** (`ARRAY` + `CHECKBOX_GROUP`), so it renders as
|
|
336
|
+
plain checkboxes here. Only `identifier` distinguishes it — branch on that if the brief wants the
|
|
337
|
+
images.
|
|
141
338
|
|
|
142
339
|
### Validation — schema-driven on the client, authoritative on the server
|
|
143
340
|
|
|
144
|
-
The schema carries the validation rules too: `required`, the `format` (EMAIL/PHONE/URL), and
|
|
341
|
+
The schema carries the validation rules too: `required`, the `format` (EMAIL/PHONE/URL), and
|
|
342
|
+
`minLength`/`maxLength`/`pattern`. **Two layers, and the split matters:**
|
|
145
343
|
|
|
146
|
-
**Server (authoritative).** `createSubmission` enforces the field's `validation` block server-side.
|
|
344
|
+
**Server (authoritative).** `createSubmission` enforces the field's `validation` block server-side.
|
|
345
|
+
Any violation — missing required, bad email, too short/long, pattern mismatch — comes back under
|
|
346
|
+
`err.details.validationError.fieldViolations[]` with an `errorPath` and an `errorType`. You **must**
|
|
347
|
+
map these back to per-input errors (see the mapping in "Submitting"); this is the backstop that
|
|
348
|
+
always holds even if a rule is missed client-side.
|
|
147
349
|
|
|
148
|
-
**Client (schema-driven UX).** Pre-validate from the *same projected constraints* so the user gets
|
|
350
|
+
**Client (schema-driven UX).** Pre-validate from the *same projected constraints* so the user gets
|
|
351
|
+
inline feedback before a round-trip — and **derive every check from the schema, never from the field
|
|
352
|
+
name.** ⚠️ The common mistake (seen in practice) is keying the email check on `target === "email"`;
|
|
353
|
+
do it off `format` so an owner-added PHONE/URL/length rule is honored with no code change:
|
|
354
|
+
|
|
355
|
+
**⚠️ No user-visible example value may be hardcoded to one locale.** Phone, postcode/ZIP, currency,
|
|
356
|
+
date or address examples in placeholders, hint text and error copy all derive from the **site's
|
|
357
|
+
country** — a `+44`- or US-only example shipped to every site is a locale bug, not a default. And an
|
|
358
|
+
illustrative *phone* number must come from that country's **regulator-reserved fictional range**,
|
|
359
|
+
never a plausible-looking one: a real number risks reaching a real person.
|
|
360
|
+
|
|
361
|
+
**Resolve `SITE_COUNTRY` once** (ISO-3166 alpha-2), in this order, and reuse it:
|
|
362
|
+
|
|
363
|
+
1. the site context you already hold, if the run fetched one — `sites[].properties.locale.country`;
|
|
364
|
+
2. else the Site Properties API — `GET https://www.wixapis.com/site-properties/v4/properties` →
|
|
365
|
+
`properties.locale.country` (SDK: `@wix/business-tools` `siteProperties.getSiteProperties()`);
|
|
366
|
+
3. else infer from the brief (a stated location, an address, a phone dialling code);
|
|
367
|
+
4. else **default `US`**.
|
|
149
368
|
|
|
150
369
|
```js
|
|
370
|
+
// Phone example shown to visitors (placeholder + error copy), derived from SITE_COUNTRY — NEVER
|
|
371
|
+
// hardcoded to one locale. Every value is a regulator-RESERVED fictional number for that country, so
|
|
372
|
+
// no real subscriber is ever printed — and being display-only it needn't pass Wix's E.164 check
|
|
373
|
+
// (submitting one would 400; see the sidebar). Add a market only after verifying its reserved range
|
|
374
|
+
// in the national numbering plan — never invent a number.
|
|
375
|
+
const PHONE_EXAMPLE = {
|
|
376
|
+
US: '+1 201 555 0123', CA: '+1 416 555 0123', // NANP 555-0100–0199 reserved for fiction
|
|
377
|
+
GB: '+44 7700 900123', // Ofcom drama range 07700 900xxx
|
|
378
|
+
IE: '+353 20 910 0001', // ComReg reserved 020 91x xxxx
|
|
379
|
+
AU: '+61 491 570 006', // ACMA reserved mobile range
|
|
380
|
+
FR: '+33 1 99 00 00 01', // ARCEP Île-de-France 01 99 00 xx xx reserved
|
|
381
|
+
DE: '+49 30 23125 000', // BNetzA Berlin 030 23125 xxx reserved
|
|
382
|
+
SE: '+46 70 174 06 05', // PTS reserved 070 174 06xx
|
|
383
|
+
KR: '+82 2 540 0000', // Seoul 02-540-xxxx reserved
|
|
384
|
+
};
|
|
385
|
+
// A PHONE field may narrow or preselect its country (`allowedCountryCodes` / `defaultCountryCode`,
|
|
386
|
+
// both projected above). Prefer the FIELD's country over the site's, so the example shown is one the
|
|
387
|
+
// field would actually accept; fall back to the site's, then to US (the default above).
|
|
388
|
+
const phoneCountry = (field) =>
|
|
389
|
+
field.defaultCountryCode ?? field.allowedCountryCodes?.[0] ?? SITE_COUNTRY;
|
|
390
|
+
const phoneExample = (field) => PHONE_EXAMPLE[phoneCountry(field)] ?? PHONE_EXAMPLE.US;
|
|
391
|
+
|
|
151
392
|
function fieldError(field, raw) {
|
|
152
393
|
const v = (raw ?? '').trim();
|
|
153
394
|
if (field.required && !v) return `${field.label} is required.`;
|
|
@@ -156,67 +397,284 @@ function fieldError(field, raw) {
|
|
|
156
397
|
if (field.maxLength && v.length > field.maxLength) return `${field.label} must be at most ${field.maxLength} characters.`;
|
|
157
398
|
if (field.format === 'EMAIL' && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(v)) return 'Please enter a valid email address.';
|
|
158
399
|
if (field.format === 'URL' && !/^https?:\/\/.+/.test(v)) return 'Please enter a valid URL.';
|
|
159
|
-
|
|
400
|
+
// PHONE is E.164 server-side: leading +, country code, digits only. Strip formatting first —
|
|
401
|
+
// visitors add spaces, dashes and parens, and rejecting those is a UX bug, not validation.
|
|
402
|
+
// Submit the NORMALIZED value, not the raw one.
|
|
403
|
+
const phone = v.replace(/[\s()\-.]/g, '');
|
|
404
|
+
if (field.format === 'PHONE' && !/^\+[1-9]\d{6,14}$/.test(phone))
|
|
405
|
+
return `Use international format, e.g. ${phoneExample(field)}.`;
|
|
160
406
|
if (field.pattern && !new RegExp(field.pattern).test(v)) return `${field.label} is not in the expected format.`;
|
|
161
407
|
return '';
|
|
162
408
|
}
|
|
163
409
|
```
|
|
164
410
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
411
|
+
**⚠️ A client check that is laxer than the server's is worse than none** — it guarantees the visitor
|
|
412
|
+
learns about the problem only after a round trip, in the server's wording rather than yours. Every
|
|
413
|
+
rule here must be at least as strict as the server's, and the value you submit must be the normalized
|
|
414
|
+
one the check passed.
|
|
415
|
+
|
|
416
|
+
Run it over the projected `inputs` on submit (and on blur — see UX below); block the submit if any
|
|
417
|
+
returns non-empty. The `<input>`/`<textarea>` also carry `minLength`/`maxLength`/`pattern` and (for
|
|
418
|
+
text) the format-derived `type` from the render step, so native constraints reinforce the JS checks.
|
|
419
|
+
**Don't hardcode a fixed field list or a per-field rule** — both the render and the validation read
|
|
420
|
+
the live schema, so a dashboard-added constraint (a new `maxLength`, a stricter `pattern`) takes
|
|
421
|
+
effect on the site with no code change.
|
|
422
|
+
|
|
423
|
+
> **`PHONE` is E.164, validated in two layers.** First the shape — leading `+`, country code, digits
|
|
424
|
+
> only; spaces, dashes, parens and a national leading `0` all fail with `must match format "phone"`.
|
|
425
|
+
> Then a per-country length/prefix check — `+99889899889` returns `Phone number for the country code
|
|
426
|
+
> provided is invalid`. A number in a country's *reserved* range — including the fictional example we
|
|
427
|
+
> show — is rejected with the misleading `Phone number's country code must correspond to one from
|
|
428
|
+
> allowed countries`; **the country is fine, the number isn't.** An allow-list *does* exist
|
|
429
|
+
> (`validation.phoneOptions.allowedCountryCodes`, projected as `allowedCountryCodes`), but it is not
|
|
430
|
+
> what fires here — widening or clearing it won't help. Never submit the example: it's display-only.
|
|
431
|
+
|
|
432
|
+
**Take only the ORDER from `steps[]`, not the geometry** — `width`, multi-column and multi-page are a
|
|
433
|
+
Phase-2 concern the frontend's own layout replaces.
|
|
170
434
|
|
|
171
435
|
### Submitting (create a submission)
|
|
172
436
|
|
|
173
|
-
Collect the input values into a **`submissions` object keyed by `target`**, and call
|
|
437
|
+
Collect the input values into a **`submissions` object keyed by `target`**, and call
|
|
438
|
+
`createSubmission`. Doc:
|
|
439
|
+
<https://dev.wix.com/docs/api-reference/crm/forms/form-submissions/create-submission?apiView=SDK>
|
|
174
440
|
|
|
175
441
|
```js
|
|
176
442
|
import { submissions } from '@wix/forms'; // Astro: call directly. Non-Astro: client.submissions
|
|
177
443
|
|
|
178
444
|
async function submitContact(formEl) {
|
|
179
|
-
|
|
180
|
-
|
|
445
|
+
// Flat fields land as `target` → value. Address sub-inputs are named `target/sub`, so fold any
|
|
446
|
+
// slashed key back into a nested object — the shape an ADDRESS field's `target` expects.
|
|
447
|
+
const arrayTargets = new Set(inputs.filter((f) => f.multiple).map((f) => f.target)); // multi-choice targets
|
|
448
|
+
const values = {};
|
|
449
|
+
for (const [name, value] of new FormData(formEl)) {
|
|
450
|
+
const slash = name.indexOf('/'); // address sub-inputs are `target/sub`
|
|
451
|
+
if (slash !== -1) { (values[name.slice(0, slash)] ??= {})[name.slice(slash + 1)] = value; continue; } // → { sub: value }
|
|
452
|
+
if (arrayTargets.has(name)) (values[name] ??= []).push(value); // multi-choice → ARRAY of checked values
|
|
453
|
+
else values[name] = value; // single value: text / dropdown / radio / …
|
|
454
|
+
}
|
|
455
|
+
const { _id, status } = await submissions.createSubmission({
|
|
181
456
|
formId: SEEDED_FORM_ID, // from seeded.forms[].formId
|
|
182
|
-
submissions:
|
|
457
|
+
submissions: values, // map of target -> value (or -> nested object, for an address)
|
|
183
458
|
});
|
|
184
|
-
return _id;
|
|
459
|
+
return { _id, status }; // CONFIRMED → render a thank-you (see the status note below)
|
|
185
460
|
}
|
|
186
461
|
```
|
|
187
462
|
|
|
188
|
-
**⚠️ CRITICAL: `createSubmission` takes POSITIONAL args — `createSubmission(submission, options)`,
|
|
463
|
+
**⚠️ CRITICAL: `createSubmission` takes POSITIONAL args — `createSubmission(submission, options)`,
|
|
464
|
+
NOT `createSubmission({ submission })`.** The first argument **is** the submission object
|
|
465
|
+
(`{ formId, submissions }`) directly; the optional second argument is `options` (e.g.
|
|
466
|
+
`captchaToken`). Wrapping it as `{ submission: {…} }` is the REST body shape and does not type-check
|
|
467
|
+
against the SDK.
|
|
468
|
+
|
|
469
|
+
**The `submissions` map is keyed by each field's `target`** — see
|
|
470
|
+
[About Submission Values](https://dev.wix.com/docs/api-reference/crm/forms/form-submissions/about-submission-values)
|
|
471
|
+
for the keys and the per-`inputType` value shapes. This is why the render step binds **`name` =
|
|
472
|
+
`target`** from the projected schema: collecting `FormData` then yields the right keys by
|
|
473
|
+
construction, with no hand-maintained list to drift.
|
|
474
|
+
|
|
475
|
+
**⚠️ Two rejections that are SEED bugs, not frontend bugs** — don't mangle the frontend key or value:
|
|
476
|
+
- An `UNKNOWN_VALUE_ERROR` on a key that *is* in the schema means the field was seeded without a
|
|
477
|
+
`validation` block, and that block is what registers the target as an accepted value (About Form
|
|
478
|
+
Fields, "Validation"). It only surfaces once someone actually fills that field in, since an empty
|
|
479
|
+
value is dropped before validation.
|
|
480
|
+
- A `NOT_ALLOWED_VALUE_ERROR` on a choice field means the seed's `options[].value` and its validation
|
|
481
|
+
enum disagree — the two declarations must match (About Form Fields, "Choice fields").
|
|
482
|
+
|
|
483
|
+
Both are fixed in `setup-forms.md` STEP 2.
|
|
484
|
+
|
|
485
|
+
**⚠️ A resolved promise is not always a recorded submission.** Read `status` from the result: for the
|
|
486
|
+
Wix Forms namespace it is `CONFIRMED` (recorded — show the thank-you), but a form that collects
|
|
487
|
+
payment returns `PAYMENT_WAITING` and some namespaces return `PENDING`, neither of which is recorded
|
|
488
|
+
or visible to the owner yet
|
|
489
|
+
([Submission status](https://dev.wix.com/docs/api-reference/crm/forms/form-submissions/introduction#submission-status)).
|
|
490
|
+
Since this renderer skips `PAYMENT` fields, treat anything other than `CONFIRMED` as "not done yet"
|
|
491
|
+
rather than showing a success state.
|
|
492
|
+
|
|
493
|
+
**⚠️ Per-field validation errors — the SDK buries them two levels deeper than the docs' shape.** The
|
|
494
|
+
documented entries (`errorPath`, `errorType`, `errorMessage`, `params` — see
|
|
495
|
+
[Validation errors](https://dev.wix.com/docs/api-reference/crm/forms/form-submissions/introduction#validation-errors))
|
|
496
|
+
arrive under **`err.details.validationError.fieldViolations[]`, each with its own `data.errors[]`
|
|
497
|
+
array**. Flatten that and **name each input by its `errorPath`** so the message lands on the right
|
|
498
|
+
control instead of only a form-level banner — that is why the address render names its sub-inputs
|
|
499
|
+
`${target}/${sub}`, matching the server's own nested path. Then write every message from `errorType`
|
|
500
|
+
plus the field's projected schema (`label`, `format`, `minLength`/`maxLength`); the docs' rule against
|
|
501
|
+
showing `errorMessage` is hard here — it goes to `console.debug` only:
|
|
502
|
+
|
|
503
|
+
```js
|
|
504
|
+
const FORMAT_COPY = { // used for FORMAT_ERROR, keyed by the field's validation format
|
|
505
|
+
EMAIL: () => 'Enter a valid email address.',
|
|
506
|
+
PHONE: (f) => `Use international format, e.g. ${phoneExample(f)}.`, // field/site-derived country
|
|
507
|
+
URL: () => 'Enter a full URL starting with https://',
|
|
508
|
+
DATE: () => 'Choose a valid date.',
|
|
509
|
+
};
|
|
510
|
+
const COPY = { // errorType → visitor-facing copy
|
|
511
|
+
REQUIRED_VALUE_ERROR: (f) => `${f.label} is required.`,
|
|
512
|
+
MIN_LENGTH_ERROR: (f) => `${f.label} must be at least ${f.minLength} characters.`,
|
|
513
|
+
MAX_LENGTH_ERROR: (f) => `${f.label} must be at most ${f.maxLength} characters.`,
|
|
514
|
+
FORMAT_ERROR: (f) => FORMAT_COPY[f.format]?.(f) ?? `Please check ${f.label}.`,
|
|
515
|
+
PATTERN_ERROR: (f) => `${f.label} is not in the expected format.`,
|
|
516
|
+
NOT_ALLOWED_VALUE_ERROR:(f) => `Choose one of the listed options for ${f.label}.`, // seed gap — see above
|
|
517
|
+
TYPE_ERROR: (f) => `Please check ${f.label}.`,
|
|
518
|
+
UNKNOWN_VALUE_ERROR: (f) => `Please check ${f.label}.`, // usually a seed gap — see above
|
|
519
|
+
};
|
|
520
|
+
|
|
521
|
+
// Unrecognized errorType MUST degrade to safe copy — the enum grows, and MIN/MAX_VALUE_ERROR,
|
|
522
|
+
// MIN/MAX_ITEMS_ERROR and DISABLED_FORM_ERROR are all reachable without being mapped above.
|
|
523
|
+
function copyFor(field, fe) {
|
|
524
|
+
const write = COPY[fe.errorType];
|
|
525
|
+
if (write) return write(field);
|
|
526
|
+
console.debug('unmapped form validation error', fe.errorPath, fe.errorType, fe.errorMessage);
|
|
527
|
+
return field ? `Please check ${field.label}.` : 'Please check the highlighted fields.';
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
const fieldErrors = {}; // errorPath → visitor-facing copy
|
|
531
|
+
for (const v of (err?.details?.validationError?.fieldViolations ?? []))
|
|
532
|
+
for (const fe of (v?.data?.errors ?? [])) {
|
|
533
|
+
if (!fe.errorPath || fieldErrors[fe.errorPath]) continue;
|
|
534
|
+
// Nested paths (`address/subdivision`, `attachments/0/fileId`) belong to the field named by the
|
|
535
|
+
// FIRST segment; `fieldByTarget` is the projected `inputs` indexed by `target`.
|
|
536
|
+
fieldErrors[fe.errorPath] = copyFor(fieldByTarget[fe.errorPath.split('/')[0]], fe);
|
|
537
|
+
}
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
`fieldErrors` is then exactly what the render reads (`fieldErrors[name]`), keyed by the same string
|
|
541
|
+
the inputs are named with.
|
|
542
|
+
|
|
543
|
+
### UX — validate as they go, show the state on the field
|
|
544
|
+
|
|
545
|
+
**Validate on blur, not only on submit.** Making a visitor reach the submit button to learn that a
|
|
546
|
+
field they left three inputs ago is wrong is a poor experience — catch it as they leave the field.
|
|
547
|
+
Run `fieldError` on each control's `blur`; once a field has been flagged, re-run on `input` so the
|
|
548
|
+
message clears the moment they fix it. **Don't** validate on the first keystroke of an untouched field — that flags a
|
|
549
|
+
required field red before they've had a chance to type. Submit still runs the full pass as the
|
|
550
|
+
backstop.
|
|
551
|
+
|
|
552
|
+
**Show invalid state on the control, not only in the error text.** A message under a tall form is
|
|
553
|
+
easy to miss — give the control itself a visible affordance. Key it off the **same `aria-invalid`
|
|
554
|
+
attribute** the validation already sets (per Accessibility below), so the visual and the assistive-tech
|
|
555
|
+
state can't drift:
|
|
556
|
+
|
|
557
|
+
```css
|
|
558
|
+
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"],
|
|
559
|
+
fieldset[aria-invalid="true"] { border-color: #c0392b; outline-color: #c0392b; }
|
|
560
|
+
```
|
|
561
|
+
|
|
562
|
+
For a choice group the attribute is on the `<fieldset>`, so style that — and clear it the same way it
|
|
563
|
+
was set: when `fieldError` returns empty, remove `aria-invalid` and the border goes with it. Don't
|
|
564
|
+
track a separate `.has-error` class in parallel; one source of truth avoids a field that looks valid
|
|
565
|
+
but reads invalid (or the reverse).
|
|
566
|
+
|
|
567
|
+
### Accessibility (the inputs are generated — one slip lands on every field)
|
|
189
568
|
|
|
190
|
-
|
|
569
|
+
Because every control is generated from the schema, an accessibility mistake is systematic: it hits
|
|
570
|
+
every field of every form. The render model already carries what's needed
|
|
571
|
+
(`target`, `label`, `required`, `options`) — wire it up.
|
|
191
572
|
|
|
192
|
-
|
|
573
|
+
**Associate each error with its control.** Give the error a deterministic id from the *same key as
|
|
574
|
+
the errorPath* (`err-${target}`, nested `err-${target}/${sub}`) and point the control at it with
|
|
575
|
+
`aria-describedby`. The error element must:
|
|
576
|
+
- be `role="alert"` (or `aria-live="polite"`) so a message appearing *after* submit is announced —
|
|
577
|
+
`aria-describedby` alone only reads on focus;
|
|
578
|
+
- **persist in the DOM**, emptied/filled — conditionally rendering it (`{err && …}`) destroys the
|
|
579
|
+
live region and nothing is announced; hide the empty state with CSS (`.error:empty{display:none}`),
|
|
580
|
+
never by unmounting;
|
|
581
|
+
- carry `aria-invalid` **only when invalid** — pass `undefined`, not `"false"`, so a clean field has
|
|
582
|
+
no attribute.
|
|
193
583
|
|
|
194
|
-
|
|
584
|
+
```jsx
|
|
585
|
+
const errorId = `err-${field.target}`; // nested: `err-${target}/${sub}` — same key as errorPath
|
|
586
|
+
<input name={field.target} aria-describedby={errorId} aria-invalid={Boolean(err) || undefined} … />
|
|
587
|
+
<p className="error" id={errorId} role="alert">{err}</p>
|
|
588
|
+
```
|
|
195
589
|
|
|
196
|
-
|
|
590
|
+
**A choice group's error attaches to the `<fieldset>`, not a radio.** Radio (`RADIO_GROUP`) and
|
|
591
|
+
multi-choice (`inputType: "ARRAY"`) groups have no single control to describe — put `aria-describedby`
|
|
592
|
+
(and `aria-required` for a required group) on the fieldset the render already emits; pointing it at
|
|
593
|
+
one radio leaves the message unreachable from the other options.
|
|
594
|
+
|
|
595
|
+
**⚠️ Marking a group invalid is a `RadioNodeList` trap.** `form.elements.namedItem(target)` returns
|
|
596
|
+
an `HTMLElement` for a text field or `<select>`, but a **`RadioNodeList`** for a radio/checkbox group
|
|
597
|
+
— so a guard like `if (control instanceof HTMLElement)` silently skips every choice group (the visual
|
|
598
|
+
`.has-error` styling still applies, so it's easy to miss). Handle both shapes:
|
|
197
599
|
|
|
198
600
|
```js
|
|
199
|
-
const
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
601
|
+
const control = form.elements.namedItem(target);
|
|
602
|
+
const nodes = control instanceof RadioNodeList ? Array.from(control)
|
|
603
|
+
: control instanceof HTMLElement ? [control] : [];
|
|
604
|
+
for (const node of nodes)
|
|
605
|
+
message ? node.setAttribute('aria-invalid', 'true') : node.removeAttribute('aria-invalid');
|
|
204
606
|
```
|
|
205
607
|
|
|
608
|
+
**On a blocked submit, focus the first invalid control — don't just scroll to it.** `scrollIntoView`
|
|
609
|
+
moves the viewport and nothing else; a keyboard/screen-reader user is left where they were. Focusing
|
|
610
|
+
it lets `role="alert"` / `aria-describedby` announce what failed.
|
|
611
|
+
|
|
612
|
+
```js
|
|
613
|
+
form.querySelector('[aria-invalid="true"]')?.focus(); // for a group, that's its first radio
|
|
614
|
+
```
|
|
615
|
+
|
|
616
|
+
**Required needs more than the `*`.** The bare ` *` the render adds is read as "star" or skipped —
|
|
617
|
+
keep it but hide it from AT (`aria-hidden="true"`) and let the control's `required` attribute (or
|
|
618
|
+
`aria-required` on a group) carry the meaning. Do both; never the glyph alone.
|
|
619
|
+
|
|
620
|
+
**Every control needs a real name.** The projection falls back to `label ?? target`, so a seed that
|
|
621
|
+
omits a label announces as `person_name` — render a real `<label>`; a `placeholder` is not a label
|
|
622
|
+
(it disappears on input and fails contrast).
|
|
623
|
+
|
|
624
|
+
**Announce success too.** Swapping the form for a thank-you block is a silent DOM change — give the
|
|
625
|
+
success region `role="status"` (or move focus to its heading with `tabindex="-1"`), or the user is
|
|
626
|
+
left on a button that appears to have done nothing.
|
|
627
|
+
|
|
628
|
+
Don't reach for `role="form"`, an `aria-label` on a native input that already has a `<label>`, or a
|
|
629
|
+
custom `role="radio"` — native radios inside a `<fieldset>` are already a correct radiogroup with
|
|
630
|
+
arrow-key selection.
|
|
631
|
+
|
|
206
632
|
### Spam protection (only if the site raised it)
|
|
207
633
|
|
|
208
|
-
The seed leaves `spamFilterProtectionLevel` at its default (`ADVANCED`), and an anonymous visitor
|
|
634
|
+
The seed leaves `spamFilterProtectionLevel` at its default (`ADVANCED`), and an anonymous visitor
|
|
635
|
+
submit **still succeeds without a captcha token** on the headless SDK path. So you normally pass
|
|
636
|
+
**no** `options`. Only if a site is configured to *require* a CAPTCHA do you need to solve one and
|
|
637
|
+
pass it as the second arg: `createSubmission(submission, { captchaToken })`. Don't add captcha
|
|
638
|
+
plumbing speculatively — the default path needs none.
|
|
209
639
|
|
|
210
640
|
---
|
|
211
641
|
|
|
212
642
|
## Conclusion
|
|
213
643
|
A correct Wix Forms frontend:
|
|
214
|
-
- **reads the live schema** with the **`forms`** export of **`@wix/forms`**
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
-
|
|
218
|
-
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
644
|
+
- **reads the live schema** with the **`forms`** export of **`@wix/forms`**
|
|
645
|
+
(`getForm`/`listForms`/`queryForms`) on the **plain visitor token — NO `auth.elevate`**: the schema
|
|
646
|
+
read is visitor-accessible on every framework incl. a pure SPA, despite the docs marking it
|
|
647
|
+
owner-scoped;
|
|
648
|
+
- renders **schema-driven** — projects `form.formFields` into a render model and generates one input
|
|
649
|
+
per field, ordered by `steps[]`, so a dashboard field add/remove/relabel or a tightened constraint
|
|
650
|
+
reflects with no code change. **Derives both options-block names** from the `inputType` /
|
|
651
|
+
`componentType` enums rather than hardcoding a fallback chain, carries the owner's `default`
|
|
652
|
+
prefill, and **skips the input types it has no control for** (`BOOLEAN`, `WIX_FILE`, `PAYMENT`,
|
|
653
|
+
`SCHEDULING`) instead of letting them fall through to a text input;
|
|
654
|
+
- **validates schema-driven on the client and treats the server as authoritative**: pre-checks
|
|
655
|
+
`required` + `minLength`/`maxLength`/`pattern` + format **keyed off `field.format`, never the
|
|
656
|
+
field name**, with each client rule **at least as strict as the server's** and the **normalized**
|
|
657
|
+
value (e.g. E.164 phone) submitted — never the raw one; always maps `createSubmission`'s
|
|
658
|
+
`fieldViolations[].data.errors[].errorPath` back to per-input errors as the backstop, writes every
|
|
659
|
+
visitor-facing message from **`errorType`** plus the field's projected schema (**never** parsing or
|
|
660
|
+
displaying the validator's `errorMessage`), and defaults an unrecognized `errorType` to safe copy;
|
|
661
|
+
- shows any user-visible example — a phone number above all — for the **field's own** country
|
|
662
|
+
(`allowedCountryCodes` / `defaultCountryCode`, else the site's), always from that country's
|
|
663
|
+
regulator-reserved fictional range, and never submits it;
|
|
664
|
+
- imports the **`submissions`** export of **`@wix/forms`** and calls
|
|
665
|
+
**`submissions.createSubmission(submission, options)`** — **positional args**, the submission
|
|
666
|
+
object first (never `{ submission }`-wrapped) — binding each input's **`name` = the schema's
|
|
667
|
+
`target`** so the `submissions` map is keyed by `target` by construction;
|
|
668
|
+
- submits on the **plain visitor token with NO `auth.elevate`** (anonymous submit works; a pure SPA
|
|
669
|
+
can't elevate anyway) and, at the default `ADVANCED` protection, **no captcha**;
|
|
670
|
+
- **only writes submissions** — reading them back is owner-only — and treats
|
|
671
|
+
**`status === "CONFIRMED"`**, not a resolved promise, as the signal to show the thank-you; reads
|
|
672
|
+
the created id as **`result._id`**, never `result.id`;
|
|
673
|
+
- is **accessible by construction** (the inputs are generated, so a slip repeats on every field):
|
|
674
|
+
each error carries a deterministic id from its `errorPath` and is referenced by `aria-describedby`
|
|
675
|
+
+ `role="alert"` and persisted (not conditionally unmounted); a choice group's error and
|
|
676
|
+
`aria-invalid` attach to the `<fieldset>` (mind the `RadioNodeList` from `form.elements.namedItem`);
|
|
677
|
+
a blocked submit **focuses** the first invalid control; `required` is programmatic, not just `*`;
|
|
678
|
+
and the success state is announced (`role="status"`);
|
|
679
|
+
- treats an `UNKNOWN_VALUE_ERROR` on a correctly-spelled target, or a `NOT_ALLOWED_VALUE_ERROR` on a
|
|
680
|
+
choice field, as a **seed** gap to fix in `setup-forms.md` — not a frontend bug.
|