[Bug]: CMS-native form rejects every select value ("invalid_option") because validation compares against option.id, while form controls send option.value
Summary
CMS-native form (base.form, mode cms) whose target table has a Select field can never be submitted. The server answers 400 Invalid form values with {"fieldId":"…","code":"invalid_option","message":"Choose one of the allowed options."} for every option the visitor picks.
The form side and the validation side use different option identifiers:
- The form controls send the option's
value, for examplegeneral_request. The editor's own "insert missing field" helper buildsbase.optionnodes withvalue: option.value(src/admin/pages/site/panels/PropertiesPanel/formSettingsAnalysis.ts, around line 242).option.valueis also the slug authors see and edit in the Data tab ("Field behavior → Options", right-hand column). src/core/forms/validation.tsonly accepts the option'sid, the random nanoid generated innewFieldDialogModel.ts({ id: nanoid(), label, value: slugifyOptionValue(label) }). Authors never see that id in the UI:
// src/core/forms/validation.ts (origin/main 112d7442, lines 222–227)
if (field.type === 'select' && typeof value === 'string') {
const allowed = new Set(field.options.map((option) => option.id))
if (!allowed.has(value)) {
return { fieldId: field.id, code: 'invalid_option', message: 'Choose one of the allowed options.' }
}
}
multiSelect has the same check (lines 229–233).
Proposed fix
Accept both id and value in the form validation and normalise to the stored representation, which is the option id. The Data grid's CellDisplayRenderer already resolves both: options.find((o) => o.id === value || o.value === value). Issue #488 also shows that cells and loops work with the id.
function resolveOptionId(field: { options: { id: string; value: string }[] }, raw: string): string | null {
const match = field.options.find((option) => option.id === raw || option.value === raw)
return match ? match.id : null
}
// select
if (field.type === 'select' && typeof value === 'string') {
const id = resolveOptionId(field, value)
if (id === null) return { fieldId: field.id, code: 'invalid_option', message: 'Choose one of the allowed options.' }
// store `id` instead of the raw value (adjust the caller so the coerced value is replaced)
}
// multiSelect: map every item through resolveOptionId, fail if any is null
Because validateCoercedValue currently only returns an error, the normalisation can sit in coerceFieldValue for select / multiSelect. That function already has field, so the stored cell becomes the option id while the error path stays the same.
Suggested tests (src/core/forms/validation.test.ts):
- select accepts
option.valueand storesoption.id - select still accepts
option.id(backwards compatible) - select rejects an unknown string with
invalid_option - multiSelect with mixed id/value items stores ids; one unknown item →
invalid_option
Steps to reproduce
- In the Data workspace, create a
datatable with a Select fieldtopicand options, e.g. label "General request" → valuegeneral_request. - In the Site editor, add a
base.form(mode CMS-native) with that table as target. Add the field with the setup block ("insert missing field") or bind an existingbase.selectwith options whose values are the option values. - Publish, open the page, choose "General request", submit.
Expected behavior
The submission is accepted and the row stores the chosen option, just like when the option is picked in the Data grid.
Actual behavior
POST /_instatic/form/submit → 400
{"error":"Invalid form values","errors":[{"fieldId":"topic","code":"invalid_option","message":"Choose one of the allowed options."}]}
No select field can be submitted through a form, not even one created by Instatic's own form setup helper. The only workaround is to change the field type to Text.
Version or commit
0.0.20
Deployment mode
Docker Compose with SQLite
Logs or screenshots