I have a form with two dependent field.
If one field changes, it can change the required state of the other.
I try to change state setRequired(value) in the ValueChangeListener, the red asterisk does not appear / disappear above the field. If I change the style, it changes the view, but setRequired does not. Why?
What kind of field components do you use? And can you share your code?
Hi Anastasia,
It seems my problem related to CustomLayout I use in my form.
If I use VerticalLayout etc. the required mark visible.
With CustomLayout only when I refresh the whole page, changes the view state.
When I set a style to my field, the style is added immediately to the view.
Here is my test code:
final ComboBox cb1 = new ComboBox("C1", Arrays.asList("A","AA"));
cb1.setNullSelectionAllowed(false);
cb1.setValue("A");
cb1.setRequired(true);
final ComboBox cb2 = new ComboBox("C2", Arrays.asList("B","BB"));
CustomLayout layout = new CustomLayout();
layout.setTemplateContents("<div location=\"cb1\"></div><div location=\"cb2\"></div>");
layout.addComponent(cb1, "cb1");
layout.addComponent(cb2, "cb2");
final Window w = new Window("Required state change test", layout);
w.setWidth("400px");
w.setModal(true);
w.center();
cb1.addValueChangeListener(new Property.ValueChangeListener() {
@Override
public void valueChange(Property.ValueChangeEvent event) {
System.out.println(cb1.getValue());
cb2.setRequired("AA".equalsIgnoreCase(cb1.getValue().toString()));
System.out.println(cb2.isRequired());
}
});
UI.getCurrent().addWindow(w);
This seems to be reason: https://dev.vaadin.com/ticket/19827
Hard to validate fields in a CustomLayout, if the caption doesn’t updating.
Can anybody suggest a workaround to update caption in a CustomLayout?