Binding does not work correctly with radio button group

firstName = new TextField("First name");
lastName = new TextField("Last name");
username = new TextField("Username");
password = new PasswordField("Password");
dob = new DatePicker("Date of birth");
sex = new RadioButtonGroup<>();
sex.setLabel("Sex");
sex.setItems(new ArrayList<>(Arrays.asList(MALE, FEMALE)));
sex.setRenderer(new TextRenderer<>(Sex::getName));
email = new EmailField("Email");
binder.forField(firstName).asRequired("First name is required").bind(User::getFirstName, User::setFirstName);
binder.forField(lastName).asRequired("Last name is required").bind(User::getLastName, User::setLastName);
binder.forField(username).asRequired("Username is required").bind(User::getUsername, User::setUsername);
binder.forField(password).asRequired("Password is required").bind(User::getPassword, User::setPassword);
binder.forField(dob).asRequired("Date of birth is required").bind(User::getDateOfBirth, User::setDateOfBirth);
binder.forField(sex).asRequired("Sex is required").bind(User::getSex, User::setSex);
binder.forField(email).asRequired("Email address is required").bind(User::getEmail, User::setEmail);              
binder.removeBinding(firstName);
binder.removeBinding(lastName);
binder.removeBinding(username);
binder.removeBinding(password);
binder.removeBinding(dob);
binder.removeBinding(sex);
binder.removeBinding(email);
binder.forField(firstName).asRequired("First name is required").bind(User::getFirstName, User::setFirstName);
binder.forField(lastName).asRequired("Last name is required").bind(User::getLastName, User::setLastName);
binder.forField(username).asRequired("Username is required").bind(User::getUsername, User::setUsername);
binder.forField(password).asRequired("Password is required").bind(User::getPassword, User::setPassword);
binder.forField(dob).asRequired("Date of birth is required").bind(User::getDateOfBirth, User::setDateOfBirth);
binder.forField(sex).asRequired("Sex is required").bind(User::getSex, User::setSex);
binder.forField(email).asRequired("Email address is required").bind(User::getEmail, User::setEmail);

In the first code block, the attached form is initialized. In the second code block, I save the user data, clear all of the fields, and remove the bindings to prevent the required messages from being displayed for each field. I then attach a binder so that the next save will have the required data.

As the first screenshot shows, the required indicators disappear as each field is populated. The radio button does not have the same behavior as the other components as its required indicator never disappears.

As the second screenshot shows, removing the bindings from the fields prevents the required message from being displayed after the last save. Again, the radio button does not have the same behavior as the other components as the required message is still being displayed after the initial binding has supposedly been removed.

I assume binding with the radio button should work just like it does with the other components.

18182269.png
18182272.png

Dear Brian,

I guess for the prevention of required messages, you can use setRequiredIndicatorVisible(false) instead of removing the bindings, so there won’t be a need for reseting those again.

I wasn’t able to reproduce a bug with the explicit radio-button behavior and it probably makes sense to submit an issue to https://github.com/vaadin/vaadin-radio-button-flow/issues/new .

Best regards,
Yuriy

Unfortunately, that doesn’t produce the desired behavior. I want the user to be able to save multiple users. And with each save, all fields are required. And yet, I don’t want to see the required messages as soon as the save button is clicked. Removing the bindings and immediately binding the fields again gives the desired behavior for every field except the radio button. I tried not using a binder on the radio button and just writing my own code to handle the required logic, but without binding there’s no way to get the validation error message if the user doesn’t make a selection. Apparently, the only way to get the desired behavior is to re-create the view after every save.

Can I ask you to create an issue via https://github.com/vaadin/vaadin-radio-button-flow/issues/new, so our dev team will be able to take a look on the issue and search for possible fix / solution to that one?

Best regards