Add fields destined to the create form
Last updated
Last updated
Please be sure of your agent type and version and pick the right documentation accordingly.
This is the documentation of the forest-express-sequelize
and forest-express-mongoose
Node.js agents that will soon reach end-of-support.
forest-express-sequelize
v9 and forest-express-mongoose
v9 are replaced by v1.
Please check your agent type and version and read on or switch to the right documentation.
Context: As a user I want to be able to pass information to a create form that concerns other collections than the current one.
The use case would be for the creation of a given record to add the information needed to create a parent record if it doesn't exist yet.
Example: I have a collection lots
that belongsTo a collection buildings
and a collection owners
. If when I create a lot, the owner and building record it should belong to do not exist yet, I want to have input fields available in the lot create form so I can create them along with the lot in a single API call.
You can declare smart fields that will not be meant to display any information but solely to serve as input fields.
In my example the fields are declared as follows in the forest/lots.js
file:
When you add the fields, you can hide them in the UI and make them visible only in the create form. As you want the user to be able to search within the existing records of the parent collection you can keep the reference fields natively generated. But if the records don't exist they can fill in the input fields.
<aside> 💡 You need to make the smart fields as editable by disabling the read only parameters in the field settings
</aside>
Now you can check if an input has been provided and use it following your own custom logic.
Reprising the form shown in the video above, the attributes object looks like this:
Demo video available here ⇒