Dynamically update form according to inputted data

I’m trying to implement dynamic form: when user selects some value from a Select field, some new fileds should be added to the current form.
To achieve this I’ve implemented FormFieldFactory which makes those extra fields not visible and I’ve tried to add listener to the Select field which makes required field visible.

I’ve added ValueChangeListener the way like this:

            
field.addListener(new Property.ValueChangeListener() {
    @Override
    public void valueChange(Property.ValueChangeEvent event) {
        if (UserType.NEWCOMER.equals(event.getProperty().getValue())) {
            form.getField(SOMEFIELD).setVisible(true);
        } else {
            form.getField(SOMEFIELD).setVisible(false);
        }
    }
});

But the ValueChangeEvent fires up when user actually clicks on the Select field, not when he selects value, so it makes user to click on the Select field twice (after the first click there no value in the corresponding property so listener does nothing).

What am I doing wrong?

Not sure if this answers your question, but
here’s one example
.

Thanks a lot!
This helped:

field.setImmediate(true);