How to programmatically, in the cycle, read the fields of the form and get the values entered in these fields?

Good afternoon, colleagues.
Actually, the subj.
There is: Form of working time table editing, 31 fields with values.
Task: Summarize values without spaghetti code (there are still conditions).
Made by:

var fields = form.getComponents();
        for (Component field : fields) {
            if (field.getId().contains("day")) {
                code...
            }
        }

allows to select the fields I want.
Question: How to get the values entered into these fields?

Sincerely yours, Alex.

Hi Alex,

Cast components to io.jmix.ui.component.Field:

Collection<Component> components = form.getComponents();
for (Component component : components) {
    if (component instanceof Field) {
        Object value = ((Field<?>) component).getValue();
        // ...
    }
}
1 Like