Field dependencies problem

Hi! I’m trying to configure form field dependencies in my model, but I don’t know how to do it correctly.

I’ve got 3 fields:

linked_items:
    label: Use items from another post
    emptyOption: "-"
    type: dropdown
    options:
        1: Post with id 1
        3: Post with id 3
        4: Post with id 4
import_items:
    label: Load items of the selected post into this post
    type: switch
items:
    label: Items
    type: repeater
  1. If the linked_items field is empty, the import_items field should be disabled and its value changed to 0.
  2. If the linked_items field is not empty and the import_items field is checked, the items field value must be copied from the linked record to the current record.
  3. After import, the import_items field should be unchecked and disabled, and the value of the linked_items field should be set to empty option.
  4. The value of the import_items field should not be saved in the database (purgeable).

All of this should be executed dynamically, immediately after interaction with the fields. I tried using dependsOn and trigger, but it didn’t work. It created an infinite loop of refreshing fields.

Any idea how to do it correctly?

Check out the changeHandler property, it can refer to an Ajax handler which can refresh the fields. It’s a low level solution but can be quite useful for more complex use cases.

Otherwise, an infinite loop suggests a circular dependency. The dependency flow ideally should be one-way (if possible).