useCwaResourceModel
Use in admin tab components (app/cwa/components/*/admin/*.vue). Not for display components.
import { useCwaResourceManagerTab, useCwaResourceModel } from '#imports'
const { exposeMeta, iri } = useCwaResourceManagerTab({ name: 'Content' })
const titleModel = useCwaResourceModel<string>(iri, 'title')
defineExpose(exposeMeta)
<template>
<CwaUiFormLabelWrapper label="Title">
<CwaUiFormInput v-model="titleModel.model.value" />
</CwaUiFormLabelWrapper>
</template>
Signature
useCwaResourceModel<T>(
iri: Ref<string | undefined>, // from useCwaResourceManagerTab
property: string | string[], // the PHP entity property name (or dot-notation path)
options?: {
debounceTime?: number // default: 250ms
longWaitThreshold?: number // ms before isBusy is considered a "long wait"; default: 5000ms
}
)
iri — the reactive IRI ref returned by useCwaResourceManagerTab. This determines which resource is being edited.
property — the PHP entity property name (case-sensitive). Supports dot-notation for nested objects ('address.city') or an array of path segments (['address', 'city']). When the target value is an object, the entire root property is submitted as a merged PATCH.
<T> — optional TypeScript generic for the field type: <string>, <number>, <string | null>, etc.
Return value
const { model } = useCwaResourceModel<string>(iri, 'title')
model.value // the current field value (string | null | undefined)
Bind model.value directly in v-model:
<CwaUiFormInput v-model="titleModel.model.value" />
Setting model.value triggers a debounced PATCH. Multiple rapid changes are batched into one request.
Multiple fields
Call useCwaResourceModel once per field:
const { exposeMeta, iri } = useCwaResourceManagerTab({ name: 'Link' })
const labelModel = useCwaResourceModel<string>(iri, 'label')
const routeModel = useCwaResourceModel<string>(iri, 'route', { debounceTime: 0 })
const rawPathModel = useCwaResourceModel<string | null>(iri, 'rawPath')
Relation fields
Set a relation by assigning an IRI string:
const categoryModel = useCwaResourceModel<string | null>(iri, 'category')
// Assign:
categoryModel.model.value = '/component/categories/uuid'
// Clear:
categoryModel.model.value = null
Setting debounceTime: 0
For fields where immediate save is preferred (e.g. a route field where you need instant validation feedback), pass debounceTime: 0.