How does it work
ThereplaceFieldWriting function allows changing the behavior of any change by creating a new patch that will be applied to the record.
You should refrain from using handlers that have side effects (to perform error handling, validation, …) and use hooks instead.
Making a field read-only
Achieve this without any code in the field settings in the Forest UI.
Examples
Changing other fields in the same record
In the following example, editing or creating afullName will update both firstName and lastName fields of the record.
Having specific behavior only for updates
Define different behavior forcreations and updates.
In this example, each time the firstName field is edited, we also want to update a timestamp field.
Changing fields in related records
Handling relationships inside a
replaceFieldWriting will only work for ManyToOne and OneToOne relationships.- The
Userscollection has ajoband aportfolioIdas foreignKey - The
Portfolioscollection has atitle
job field we want also to update the title of the portfolio by the job name.
If the relationships do not exist, they will be created with the given field values.
portfolioId to update the relationships and their fields:
one-to-one relationship with the formats collection, you can update it by writing the right path.