Directory

← Back

indeterminate-checkbox

A Checkbox that toggles between 3 states: indeterminate, true, false

Author

Rating

Popularity

<100

overrides addValueChangeListener method to extend the given listener with custom logic to handle the indeterminate state.

There can only be 1 active valueChangeListener at any time. Please never remove() a listener Registration, instead you can call indeterminateCheckbox.addValueChangeListener(null). This makes sure the custom listener logic that handles indeterminate state is never lost.

When adding your own ValueChangeListener, one should always keep in mind to first check indeterminateCheckbox.isIndeterminate() before event.getValue(), because when the checkbox appears indeterminate, the underlying value is not null but rather false (because null value is not supported)

Sample code

IndeterminateCheckbox indeterminateCheckbox = new IndeterminateCheckbox();
indeterminateCheckbox.addValueChangeListener(event -> {
    if(indeterminateCheckbox.isIndeterminate()){
        // new "value" is indeterminate. (Pseudo "null")
        // warning: event.getValue() and event.isFromClient() both return false here!
    } else if(event.getValue()) {
        // new value is true
    } else {
        // new value is false
    }
});
add(indeterminateCheckbox);

Compatibility

(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.

Version

Released
2020-12-04
Maturity
EXPERIMENTAL
License
Apache License 2.0

Compatibility

Framework
Vaadin 10+
Browser
Browser Independent

indeterminate-checkbox - Vaadin Add-on Directory

A Checkbox that toggles between 3 states: indeterminate, true, false indeterminate-checkbox - Vaadin Add-on Directory
overrides `addValueChangeListener` method to extend the given listener with custom logic to handle the indeterminate state. There can only be 1 active valueChangeListener at any time. Please never `remove()` a listener Registration, instead you can call `indeterminateCheckbox.addValueChangeListener(null)`. This makes sure the custom listener logic that handles indeterminate state is never lost. When adding your own ValueChangeListener, one should always keep in mind to first check `indeterminateCheckbox.isIndeterminate()` before `event.getValue()`, because when the checkbox appears indeterminate, the underlying value is not null but rather false (because null value is not supported)
Online