Link two entities in one form
Example: Creating an employee record and linking them to a newly created job
Try it out!
Scenario
When creating a new job, you want the option of creating and linking a new employee to that job in the one form. For this example you should use the sample data supplied in the internal BudibaseDB tables.
★★★★☆
Steps
-
Add component
: Form Block -
In the Settings Panel, select the 'Jobs' Table
-
At the very bottom of the settings panel, click
Eject
- this will break down the Form Block into it's constituent parts. We can see this in the component tree. -
Add component
: Options Picker -
In the Settings Panel, enter 'ExistingEmployee' as the Field.
-
-
Set Type to 'Radio buttons'
-
Set Direction to 'Horizontal'
-
Set Default value to 'SELECT'
-
Uncheck Alphabetical
-
Set Options source to 'Custom'
-
Define options
:-
Label Value Select existing employee SELECT Create new employee NEW
-
- In the component tree, drag the Relationshipfield below the Options Picker
- Click on the
Conditions
tab Configure conditions
:Add condition
- Hide component IF
{{ Form.Fields.ExistingEmployee }}
Equals Binding NEW Save
- Hide component IF
Add component
: Container- Click on the
Conditions
tab Configure conditions
:Add condition
- Hide component IF
{{ Form.Fields.ExistingEmployee }}
Equals Binding SELECT Save
- Hide component IF
-
Add component
: Headline. Set Text to 'New Employee' -
Add component
: Field Group -
Click on the Form and set the Schema to 'Employees'
-
Click on the newly added Field Group and click
Update form fields
-
Set Type to
Two columns
-
Delete the Jobs field
-
You may also need to replace the Text Field for Address with a Long Form Field if it displays as an error.
-
Click on the Form and set the Schema back to 'Jobs'
-
Click on the 'Save' Button, enter the settings using the cog-icon and
Define actions
-
Click the
X
beside each actions so that only the Validate Form and Save Row actions remain -
Add Action
: Navigate To Screen '/jobs' -
Add Action
: Continue if / Stop if- Continue if
{{ Form.Fields.ExistingEmployee }}
Equals NEW
- Continue if
-
Add Action
: Save Row-
Set Table to 'Employees'
-
Add Column
for each form field in the Employees Field Group. Set the Value to the form field bindings, e.g.{{ Form.Fields.First Name }}
-
Add Column
for the 'Jobs' column. Set Value to{{ Action 2.Saved row._id }}
. This will get the _id of the Job that was saved in second action. -
Save
your actions!
-
Employee validation
As the select form schema is for the Jobs table, you will need to add custom validation rules to the Employee fields you want validated.
The same is also true for options that are defined by the table schema, such as Employee Level in this case.
App export
Downloads may take a few seconds.
Updated 2 months ago