Computed Field Values are fields whose values are derived from other form data. There are three primary methods to implement them depending on whether the value needs to be emitted/saved to a database.
// Method 1: Using parseValue (UI only)
// The value is synced in the UI but NOT emitted in @update:modelValue or @save.
{
id: 'fullName',
component: 'input',
parseValue: (val, { formData }) => `${formData.firstName || ''} ${formData.lastName || ''}`
}
// Method 2: Using updateField in events (Database/Event compatible)
// Triggered by other fields to update the computed field's value.
{
id: 'firstName',
events: {
'update:modelValue': (val, {formData, updateField}) => {
const { lastName = '' } = formData
const value = `${val} ${lastName}`.trim()
updateField({ id: 'fullName', value })
}
}
}
// Method 3: Combining parseValue & updateField (Self-contained & Database compatible)
// The logic is contained within the computed field itself.
{
id: 'fullName',
component: 'input',
parseValue: (val, {formData, updateField}) => {
const newValue = `${formData.firstName || ''} ${formData.lastName || ''}`.trim()
if (val !== newValue) updateField({ id: 'fullName', value: newValue })
return newValue
},
showCondition: false // Optional: hide the field while still saving data
}