Set field values in the edit form depending on the value of another field (conditional rules)

Hello!

Is it possible to add the following functionality: in the edit form of an existing record, when a value is selected in a field (for example, a one-to-many relationship field), other fields are filled in with values depending on those in the drop-down list field?

What I mean is:

There is a Order Route collection, where there is a Loading Location and Loading Date field, and there is also a Contractor Route collection, where there are exactly the same fields as in the Order Route. At the same time, Order Route and Contractor Route have a one-to-many relationship, and in the Contractor Route editing form, there is a field with a selection of records (Order Route) from the Order Route collection.

Now you can set default values for fields in the record addition form, while setting a dependency on the selected record in the Order Route field. As soon as you select a value, the corresponding fields will display the required values, configured according to the condition.

I would like to have similar functionality in the editing form - that is, the fields will not be filled in by default (when the form is opened), but at the moment of selecting a value in another field. And if the settings allow you to add conditions under which other fields will be auto-filled, then this should happen. In this case, the values that were already entered at the time the script was executed will simply be overwritten with the new values.

Below is an approximate video screenshot.
autofill-edit-form-1

You can accomplish this using linkage rules:

https://docs.nocobase.com/handbook/ui/linkage-rule

1 Like

Thank you for your suggestion, it could work, but I don’t see the “value change” event in the target field…

It’s very cool that there is such an option to set binding rules for fields, but there is no action for changing the field to trigger the trigger for my case: that is, when another value is selected in the field (or the focus is changed to another field).

How can I get this result? Is there a workaround? Or am I missing something, and is there another setting? I would appreciate any advice!

UPDATE: I may not have fully explained my idea: what I mean is that the values of other fields should only change when the target field value is changed. And, if necessary, it should be possible to manually adjust the fields values obtained (if the last value remains unchanged). Here, it is precisely the trigger for performing the action to change the field value.

I think I’ve found the right solution!

In the field linkage rules, you need to specify a comparison value ID (the relation field with a drop-down list of records from another collection) in the current editing form with the previously saved value (ID) in the same field. You need to put an inequality sign - in this case, if we change the original value (which was previously saved in the collection database), the inequality condition is met and the action condition is executed! This way, the value in the fields is saved if you need to change it manually (i.e., without changing the “trigger” field).

That’s great! You pointed me in the right direction and I figured out how to solve my problem! Thanks again for your clever idea and hint!

1 Like

@hongboji Hello!

I would like to ask a question related to this topic. I noticed that in record edit mode, I can’t set the “Value” action property for a field with a relationship type (for example, one-to-many) in the linkage rule settings. However, for other field types, the “Value” property can be set (for example, for the String field type).


At the same time, for a new record adding mode, it is possible to set a default value for the “relationship” field type - that is, in general, the request to display the desired value works. However, perhaps the display function is not enabled in the linkage rule settings?

Or am I configuring something incorrectly?

Direct link where I tried to configure the binding rules: https://a_8hwne7u84ho.v13.demo.nocobase.com/admin/on02hifb4i3/popups/49sblmzszn2/filterbytk/338414241251328/tab/du7brynzz1c/popups/iuntjlhjg6f/filterbytk/338414750859264/sourceid/338414241251328/tab/36154x06sk1

Hello, this feature is not currently supported.

Okay, thank you, I understand your answer.

However, I saw a potential opportunity on the Modern Page (version 2) — there is a special setting in the field linkage rule where you can specify a value as a result in the action. I created a separate Currency collection and placed identical link fields for this collection (many-to-one) in the Transportation and Contractor Transportation collections. The idea is that these collections are also linked to each other, and when you select Transportation, the Currency field in the Contractor Transportation collection should be filled in with the same value as the Currency field in the Transportation collection (as if copying or transferring the Currency value).

However, in the settings, it is not possible to select Currency as an “object” (as is done in the Page Classic version 1) — you must go deeper and select one of the fields (I tried to select both ID and Name ISO). But the condition/rule does not work that way…

But if I select a field (ID or Name ISO) within an object, the action does not work, and the value is not filled in the Currency field.

I tested this functionality on this page (action - edit record): https://a_8hwne7u84ho.v13.demo.nocobase.com/admin/gxpzwd86ai1/view/30a0353f123/tab/bf607d3e087/filterbytk/338414241251328/view/83061f21bba/tab/21b2dc34eeb/filterbytk/340969411903488/sourceid/338414241251328