@bimeo/directus-extension-update-data-based-on-relation-interface
v1.0.1
Published
Update data based on data from a related record
Maintainers
Readme
Update Data Based on Relation - Directus Interface Extension
This is a Directus interface extension that automatically updates a field in the current record based on data from a related record. When a user selects a value in a many-to-one (M2O) relationship field, this extension can automatically populate another field with data from the selected related record.
Features
- Automatically fills target fields when a related record is selected
- Configurable source lookup field, source field, and target field
- Real-time updates when the lookup value changes
How it Works
- Configure a source lookup field (M2O relationship)
- Select which field from the related record to copy (source field)
- Choose which field in the current record to update (target field)
- When users select a value in the lookup field, the extension automatically fetches the related data and updates the target field
Use Cases
- Auto-populate customer details when selecting a customer
- Fill in product information when choosing a product
- Set default values based on category selection
- Copy reference data from master records
Development
To run the extension in development mode with hot reloading:
npm run devThis will build the extension in watch mode without minification, allowing for faster development cycles with automatic rebuilds when files change.
Building
To build the extension for production:
npm run buildThe built extension will be output to the dist directory and can be deployed to your Directus instance.
Installation
- Copy the
distfolder to your Directus extensions directory (typicallyextensions/) - Restart your Directus instance
- The "Update data based on a relation" interface will be available in your field configuration options
Configuration
When adding this interface to a field in Directus:
- Source lookup: Select the M2O relationship field that triggers the update
- Source field: Choose which field from the related record to copy
- Target field: Select the field in the current record that will be updated
Configuration Example
If you have:
- A
customerscollection with fields likename,email - An
orderscollection with acustomer_idM2O field pointing to customers
You could configure:
- Source lookup:
customer_id - Source field:
email(from customers) - Target field:
customer_email(in orders)
Now when someone selects a customer, the customer's email will automatically populate the customer_email field.
Development Scripts
npm run build- Build for productionnpm run dev- Build in watch mode for developmentnpm run link- Link extension for local developmentnpm run validate- Validate extension structure
