Example usage:
CheckBox checkBox = CheckBox.create("Enable feature")
.setChecked(true)
.onChange(value -> DomGlobal.console.log("Checkbox state changed: " + value));
See also :
public void CheckBox()
public void CheckBox(String checkLabel)
checkLabel
The label text displayed next to the checkbox.
public void CheckBox(String label, String checkLabel)
label
The label text for the checkbox field.
checkLabel
The label text displayed next to the checkbox.
public static CheckBox create(String checkLabel)
checkLabel
The label text displayed next to the checkbox.
public static CheckBox create(String label, String checkLabel)
label
The label text for the checkbox field.
checkLabel
The label text displayed next to the checkbox.
public static CheckBox create()
public Optional<Consumer<Event>> onChange()
Returns an optional Consumer of Event that listens for change events on this CheckBox. When a change event occurs, this method checks if the CheckBox is enabled and not read-only. If both conditions are met, it updates the CheckBox's value based on its checked state.
Returns:
An optional Consumer of Event to handle change events on this CheckBox.
public CheckBox setCheckLabel(String checkLabel)
checkLabel
The label text for the checkbox.
This CheckBox instance.
public CheckBox setCheckLabel(Node checkLabel)
checkLabel
The DOM Node to be used as the label content.
This CheckBox instance.
public CheckBox setCheckLabel(IsElement<?> checkLabel)
public String getType()
Gets the type of this input field, which is always "checkbox" for CheckBox instances.
Returns:
The type of this input field, which is "checkbox."
public CheckBox toggleChecked(boolean silent)
silent
If true , change listeners will not be triggered; otherwise, they will.
This CheckBox instance.
public CheckBox toggleChecked()
This CheckBox instance.
public CheckBox toggleChecked(boolean checkedState, boolean silent)
checkedState
The desired checked state.
silent
If true , change listeners will not be triggered; otherwise, they will.
This CheckBox instance.
public Boolean getDefaultValue()
This method returns the default value for the CheckBox, which is false if no default value has been set.
Returns:
The default value of the CheckBox (false if not set).
public CheckBox withValue(Boolean value, boolean silent)
This method sets the value of the CheckBox and allows the option to perform the operation silently (without triggering change listeners).
If the provided value is null , it will use the default value instead (if set).
value
The value to set.
silent
True to perform the operation silently, false otherwise.
This CheckBox instance.
public CheckBox indeterminate()
This method sets the CheckBox to an indeterminate state.
Returns:
This CheckBox instance.
public CheckBox determinate()
This method sets the CheckBox to a determinate state.
Returns:
This CheckBox instance.
public CheckBox toggleIndeterminate(boolean indeterminate)
This method toggles the indeterminate state of the CheckBox.
indeterminate
True to set to an indeterminate state, false otherwise.
This CheckBox instance.
public CheckBox toggleIndeterminate()
This method toggles the indeterminate state of the CheckBox.
Returns:
This CheckBox instance.
public CheckBox check()
Checks the CheckBox, setting its value to true . If the CheckBox is currently paused for change listeners, the check operation can be silent. If not paused, it will trigger change listeners if any are registered.
Returns:
This CheckBox instance after the check operation.
public CheckBox uncheck()
Unchecks the CheckBox, setting its value to false . If the CheckBox is currently paused for change listeners, the uncheck operation can be silent. If not paused, it will trigger change listeners if any are registered.
Returns:
This CheckBox instance after the uncheck operation.
public CheckBox check(boolean silent)
This method checks the CheckBox, optionally allowing the operation to be performed silently (without triggering change listeners). It also sets the CheckBox to a determinate state.
silent
True to perform the operation silently, false otherwise.
This CheckBox instance.
public CheckBox uncheck(boolean silent)
This method unchecks the CheckBox, optionally allowing the operation to be performed silently (without triggering change listeners). It also sets the CheckBox to a determinate state.
silent
True to perform the operation silently, false otherwise.
This CheckBox instance.
public boolean isChecked()
This method checks whether the CheckBox is in a checked state.
Returns:
True if the CheckBox is checked, false otherwise.
public CheckBox filledIn()
This CheckBox instance.
public CheckBox filledOut()
This CheckBox instance.
public CheckBox setFilled(boolean filled)
filled
True to style the CheckBox as filled in, false to style it as filled out.
This CheckBox instance.
public Boolean getValue()
This method returns the value of the CheckBox, which is the same as whether it's checked or not.
Returns:
True if the CheckBox is checked, false otherwise.
public boolean isEmpty()
This method checks whether the CheckBox is empty, meaning it is not checked.
Returns:
True if the CheckBox is empty (unchecked), false otherwise.
public boolean isEmptyIgnoreSpaces()
This method checks whether the CheckBox is empty, ignoring spaces.
Returns:
True if the CheckBox is empty (unchecked), false otherwise.
public String getStringValue()
This method returns the string representation of the CheckBox's value, which is either "true" if checked or "false" if not checked.
Returns:
The string representation of the CheckBox's value.
public AutoValidator createAutoValidator(ApplyFunction autoValidate)
This method creates an AutoValidator instance for the CheckBox, which is used to automatically validate the CheckBox's value.
autoValidate
The function to apply for auto-validation.
An AutoValidator instance for the CheckBox.
public String getName()
This method returns the name of the CheckBox.
Returns:
The name of the CheckBox.
public CheckBox setName(String name)
This method sets the name attribute of the CheckBox's input element.
name
The name to set.
This CheckBox instance.
public CheckBox withLabel(ChildHandler<CheckBox, LabelElement> handler)
handler
The handler to apply to the label element.
This CheckBox instance.
public CheckBox withLabelTextElement(ChildHandler<CheckBox, SpanElement> handler)
handler
The handler to apply to the label text element.
This CheckBox instance.
public LabelElement getCheckLabelElement()
The label element of this CheckBox.
public LazyChild<SpanElement> getCheckLabelTextElement()
The lazy child element of the label text associated with this CheckBox.