Progress Bar remaining fields

Hey everyone,

I was wondering if there is a way to count the number of remaining empty fields and to show that on the progress bar. Also, is it possible to show the percentage or number of fields that are filled already out of the total number of fields. For example, if I am creating a new profile to an employee. The employee entity has 10 attributes, but only 5 is filled, so the progress bar will show 50% complete of his profile.

Thank you in advance

Hello, Karim!

The simpliest way is to subscribe to item property change event of datasource, count empty (or filled) fields and update your progress bar.


fieldGroup.getDatasource().addItemPropertyChangeListener(e -> {
    float filledFields = 0;
    for (FieldGroup.FieldConfig fieldConfig : fieldGroup.getFields()) {
        if (fieldGroup.getFieldValue(fieldConfig) != null) {
            filledFields++;
        }
    }

    float fieldsCount = fieldGroup.getFields().size();
    progressBar.setValue(filledFields / fieldsCount);
});

I see what you’re doing here. But what if I have the attributes in a tabbed form. So each tab has a different fieldGroup. How can I count all fieldGroups at the same time? Or is this applied on each fieldGroup with an active cursor on it???

This code works only for single FieldGroup.

Implementation depends on how your FieldGroups are linked to the data, how many datasources do you have, etc.

But the main idea is that you should subscribe to the item property change event of your datasource (or datasources) which you are interested in. When event happens you should iterate over all your FieldGroups, which are linked to this datasource (or datasources), count filled (or empty) fields and update ProgressBar.