The CWA is in heavy development
The CWA is still in alpha and not ready for production - some code and implementations are likely to change. If you would like to try out the CWA, please enjoy what we have provided and feel free to provide feedback, or get involved on GitHub.
DraftCwa Api
cwa.forms
Access the structured form view data and field errors for Form component resources.
Access the structured form view data for Form component resources.
Application code normally goes through the form composables (useCwaForm, useCwaFormInput, useCwaFormCollection — see Forms). Reach for cwa.forms directly only when building a custom form UI that the composables don't cover.
getForm(iri)
Returns a ComputedRef of the structured form view, keyed by field name:
const formView = cwa.forms.getForm('/component/forms/018e-...')
// Access a field's vars
const nameField = formView.value?.['contact[name]']
nameField?.vars.value // current value
nameField?.vars.errors // string[]
nameField?.vars.required // boolean
nameField?.vars.block_prefixes // ['form', 'text', '_contact_name'] — for type-specific rendering
getFormViewErrors(formIri, field)
Convenience computed that returns the error array for a specific field, or undefined if there are none:
const nameErrors = cwa.forms.getFormViewErrors('/component/forms/018e-...', 'contact[name]')
// nameErrors.value → ['This field is required'] or undefined
Other Methods
These are the calls the form composables make on your behalf. Field values are held per form IRI, keyed by the field's full_name.
| Method | Purpose |
|---|---|
submitForm(endpoint, body, method) | Submit the form. Resolves { success, formErrors? } and writes the response (including a 422 body) back into the resources store |
validateField(endpoint, body) | PATCH a partial body for server-side validation of a single field; the refreshed form view is saved to the store |
setFieldValue(iri, fullName, value) | Record a field's current value |
getFieldValues(iri) | All recorded values for the form, as a plain object |
clearFieldValue(iri, fullName) | Drop a recorded value (e.g. when a collection entry is removed) |
isSubmitAttempted(iri) / setSubmitAttempted(iri, attempted) | Whether submission has been attempted — used to decide when to show errors |
registerLocalEntry(iri, entry) / unregisterLocalEntries(iri, keys) | Add or remove client-side collection entries cloned from the form prototype. Returns the field keys it created |
Bodies passed to submitForm and validateField use bracketed field names (contact[name]) — they are converted to nested JSON before being sent.