platform icon indicating copy to clipboard operation
platform copied to clipboard

Could binder setter work without total validation?

Open Mrakobec opened this issue 1 year ago • 1 comments
trafficstars

Describe your motivation

Vaadin versin used: 24.3.6 I would to use setter trigger to create Entity on press checkBox (as example in my case) and i have some additional logic to provide this new entity. If I reliaze this logic and i have not valid any another binded field, this setter doesn't work and when checkbox is pressed - nothing happens.

example: 2 Entitys: Auction, Settings;

Auction{
String name;
Setting settings;
}

Settings{
Boolean isPriceHidden;
}

view:

Binder<Auction> auction ...
TextField nameField....
CheckBox hasSettingsCheckBox....
Button changeSettingsBtn...
....
changeSettingsBtn.setVisible(false);
...
binder.forField(nameField).asRequired().....
binder.forField(hasSettingsCheckBox).bind(auction -> auction .getSettings() == null, (auction, aBoolean) -> {
            if(event.getValue()){
                auction.setSettings(null);
            }
            else if(auction.getSettings() == null){
                auction.setSettings(new Settings());
            }
       changeSettingsBtn.setVisible(auction.getSettings() != null);
        });
....

Describe the solution you'd like

I like to setter works locally in exactly field, and don't wait to have all valid fields. If target field doesn't validate -> setter doesn't work - OK. If target field is valid -> setter work - OK. If target field is valid and another field is not valid -> setter doesn't work - WRONG.

Describe alternatives you've considered

now I need to use the valueChangeListener and additional validation, and this look like crutch.

Additional context

No response

Mrakobec avatar Mar 07 '24 15:03 Mrakobec

Probably related to this issue, that has been fixed in Flow and will be released in Vaadin 24.3.7

mcollovati avatar Mar 07 '24 15:03 mcollovati