Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Dynamically update form according to inputted data

Igor Korotkov
9 years ago Apr 18, 2012 2:00pm

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?

Last updated on Apr, 18th 2012
Marko Grönroos
9 years ago Apr 18, 2012 3:29pm
Igor Korotkov
9 years ago Apr 19, 2012 4:19pm