Processing between different fields of a form

Hi All,

I am still a newbie in Jmix, find it quite useful but I may have still have some basic issues. I have 2 scenarios which I cant solve easy and I think I went to a wrong approach.

  1. How can 2 fields of a form interact, for example there are 3 fields a, b, c and c= a+b so as soon as the user give data for a and b in the form i wanted to calculate the value of c.
  2. In a form i have 2 entitypicker. However the second entitypicker depends on the selection of the first entity. I tried to define a collection with an own loader (query with a paramater) but then I stuck where to set the value from the first entitypicker.

Any hints are most welcome

Thank you very much

Use ValueChangeEvent listener for fields. In the listener, check the necessary fields and fill in other fields.

....

        <form id="form" dataContainer="newEntityDc">
            <column width="350px">
                <textField id="field1Field" property="field1"/>
                <textField id="sumWithDiscount"/>
            </column>
        </form>
......

    @Autowired
    private TextField sumWithDiscount;

    @Subscribe("field1Field")
    public void onField1FieldValueChange(HasValue.ValueChangeEvent<Integer> event) {
        if (event.isUserOriginated() && event.getValue() != null) {
            sumWithDiscount.setValue(event.getValue()*0.9);
        }
    }

In a form i have 2 entitypicker. However the second entitypicker depends on the selection of the first entity. I tried to define a collection with an own loader (query with a paramater) but then I stuck where to set the value from the first entitypicker.

Look at facet dataLoadCoordinator in mamual mode. Often this is very usefull.

But note that the EntityPicker does not have the ability to filter for options.
That is, he will always show all the entities to choose. And for a dependent picker, you need to use EntityComboBox or EntitySuggestionField.

If the dataLoadCoordinator does not match, then again - listener of the ValueChangeEvent event for main EntityPicker. And in the event listener, change the query parameters to load the data into dependent EntityComboBox options container.

1 Like

Thank you Andrey, it helped me a lot ! :slightly_smiling_face: