fieldsFromSchema
Generates form-field descriptors from the properties block of a schema. Used by CnFormDialog and similar auto-generated forms. Each field descriptor includes a resolved widget name so the form can pick the right input component.
Signature
import { fieldsFromSchema } from '@conduction/nextcloud-vue'
const fields = fieldsFromSchema(schema, {
exclude: ['createdAt', 'updatedAt'],
includeReadOnly: false,
overrides: { description: { widget: 'textarea' } },
})
Parameters
| Arg | Type | Default | Description |
|---|---|---|---|
schema | object | — | Must have a properties object; otherwise []. |
options.exclude | string[] | [] | Keys to drop. |
options.include | string[] | null | null | Whitelist. |
options.overrides | object | {} | Per-key overrides merged onto the descriptor. |
options.includeReadOnly | boolean | false | When false, properties with readOnly: true are dropped. |
Returns
{
key: string,
label: string, // prop.title ?? key
description: string, // prop.description ?? ''
type: string, // prop.type ?? 'string'
format: string | null,
widget: string, // resolved — see table below
required: boolean, // derived from schema.required
readOnly: boolean,
default: any | null, // prop.default ?? null
enum: any[] | null,
items: object | null,
validation: {
minLength, maxLength, minimum, maximum, pattern
},
order: number, // prop.order ?? Infinity
}[]
Widget resolution
The widget field is resolved by the internal resolveWidget() routine with this precedence:
prop.widget— explicit hint, pass-through (custom widgets supported).prop.enum→'select'.- Type-based:
boolean→'checkbox'integer/number→'number'array+items.enum→'multiselect'array(no enum) →'tags'
- Format-based:
date-time→'datetime'date→'date'email→'email'uri/url→'url'markdown/textarea→'textarea'
prop.maxLength > 255→'textarea'.- Fallback →
'text'.
Filtering
Properties are dropped when:
prop.visible === falseprop.readOnly === trueandincludeReadOnly !== true- key in
exclude, or not ininclude(when provided) prop.type === 'object'unlessprop.widgetis set (auto-forms don't render nested objects by default; setwidget: 'json'orwidget: 'code'to opt an object property back in and letCnFormDialogrender aCnJsonViewerfor it).
Sorting
Same as the other schema helpers: prop.order ascending, alphabetical tie-break.
Related
- CnFormDialog — Primary consumer.
- columnsFromSchema, filtersFromSchema