Field visible or invisible depending on other fields value

Hi there,

I’m trying to make a field in the editor visible of invisible, depending on a the value of a field (which is a boolean) when true the field must be shown and when false the field must disappear. I used the code in the developers manual but i keep getting a nullPointerException.

This is my code:
public class EvenementEdit extends AbstractEditor {

@Inject
private CheckBox activiteitField;

@Inject
private TextField adresField;

@Subscribe
protected void onInit(InitEvent event) {
    activiteitField.addValueChangeListener(valueChangeEvent -> {
        if (Boolean.TRUE.equals(valueChangeEvent.getValue())) {
            adresField.setVisible(false);
        }
    });
}

}

any help will be welcome.

Regards LS.

I Also tried this code since the app was build in cuba 6 and migrated to cuba 7.

@Inject
private CheckBox activiteitField;

@Inject
private TextField adresField;

@Override
public void init(Map<String, Object> params) {
   activiteitField.addValueChangeListener(event -> {
        if (Boolean.TRUE.equals(event.getValue())) {
             adresField.setVisible(false);
        }
    });
}

With the same result

Hi.
Could you please share the stacktrace of exception? Also, it would be helpful if you clarify the exact version of the platform on which it was build and on which it was migrated.

Regards,
Natalia

Hi Natalia,

After going though some topics i change a few things. I’ve split the fields into more fieldgroups and now i’m trying to hide the fieldgroups, which seems nicer. I came upon this topic here, which is the same i want to do. cuba version 7.2.4 migrated from 6.10.

Thanks,

LS

I hope the answer from the topic will be useful, otherwise tell us in more detail what you want to do