1. Domino UI
  2. Forms
  3. Switch
Top Basic Docs

Basic Switch button

A customizable SwitchButton component.

This component provides a switchable button that can be toggled between ON and OFF states.

 
 Usage:
 SwitchButton button = SwitchButton.create("Label", "Off", "On");
 

See also :

Examples

Switch A button to switch between on/off states.

API Docs: SwitchButton

Constructors

public void SwitchButton(String label, String offTitle, String onTitle)
Constructor to initialize the SwitchButton with a label, off title, and on title.

label

the label of the switch button

offTitle

the title when switch is OFF

onTitle

the title when switch is ON

public void SwitchButton(String label, String onOffTitle)
Constructor to initialize the SwitchButton with a label and on/off title.

label

the label of the switch button

onOffTitle

the title for both ON and OFF states

public void SwitchButton(String label)
Constructor to initialize the SwitchButton with a label.

label

the label of the switch button

public void SwitchButton()
Default constructor to initialize the SwitchButton with default settings.

Static methods

public static SwitchButton create(String label, String offTitle, String onTitle)
Factory method to create a SwitchButton with specified label, off and on titles.

label

the label of the switch button

offTitle

the title when switch is OFF

onTitle

the title when switch is ON



Returns:

a new SwitchButton instance

public static SwitchButton create(String label, String onOffTitle)
Factory method to create a SwitchButton with specified label and on/off title.

label

the label of the switch button

onOffTitle

the title for both ON and OFF states



Returns:

a new SwitchButton instance

public static SwitchButton create()
Factory method to create a SwitchButton with no initial settings.

Returns:

a new SwitchButton instance

Public methods

public String getType()
Returns the type of the SwitchButton as a "checkbox".

Returns:

String representing the type "checkbox".

public Optional<Consumer<Event>> onChange()
Provides an event consumer for handling change events.

Returns:

Optional containing a Consumer for the change event.

public SwitchButton toggleChecked(boolean silent)
Toggles the checked state of the SwitchButton.

silent

if true, does not notify the change listeners.



Returns:

the current instance of SwitchButton .

public SwitchButton toggleChecked()
Toggles the checked state of the SwitchButton.

Returns:

the current instance of SwitchButton .

public SwitchButton toggleChecked(boolean checkedState, boolean silent)
Sets the checked state of the SwitchButton to the provided state.

checkedState

desired checked state.

silent

if true, does not notify the change listeners.



Returns:

the current instance of SwitchButton .

public Boolean getDefaultValue()
Returns the default value for the SwitchButton.

Returns:

the default value which is false if null.

public SwitchButton withValue(Boolean value, boolean silent)
Sets the value of the SwitchButton.

value

the desired value.

silent

if true, does not notify the change listeners.



Returns:

the current instance of SwitchButton .

public SwitchButton check()
Sets the SwitchButton to a checked state.

Returns:

the current instance of SwitchButton .

public SwitchButton uncheck()
Sets the SwitchButton to an unchecked state.

Returns:

the current instance of SwitchButton .

public SwitchButton check(boolean silent)
Sets the SwitchButton to a checked state.

silent

if true, does not notify the change listeners.



Returns:

the current instance of SwitchButton .

public SwitchButton uncheck(boolean silent)
Sets the SwitchButton to an unchecked state.

silent

if true, does not notify the change listeners.



Returns:

the current instance of SwitchButton .

public SwitchButton setOnTitle(String onTitle)
Sets the title for the "on" state of the SwitchButton.

onTitle

the title to be set for the "on" state.



Returns:

the current instance of SwitchButton .

public SwitchButton setOffTitle(String offTitle)
Sets the title for the "off" state of the SwitchButton.

offTitle

the title to be set for the "off" state.



Returns:

the current instance of SwitchButton .

public LazyChild<LabelElement> getOffLabelElement()
Gets a lazy child representing the "off" label element of the SwitchButton.

Returns:

the LazyChild for the "off" label element.

public LazyChild<LabelElement> getOnLabelElement()
Gets a lazy child representing the "on" label element of the SwitchButton.

Returns:

the LazyChild for the "on" label element.

public AutoValidator createAutoValidator(ApplyFunction autoValidate)
Creates an auto validator for the SwitchButton.

autoValidate

the ApplyFunction to be applied for auto-validation.



Returns:

an instance of AutoValidator for the SwitchButton.

public Boolean getValue()
Gets the value of the SwitchButton as a Boolean.

Returns:

the Boolean value representing the checked state of the SwitchButton.

public boolean isChecked()
Checks if the SwitchButton is in a checked state.

Returns:

true if the SwitchButton is checked, false otherwise.

public boolean isEmpty()
Checks if the SwitchButton is empty (unchecked).

Returns:

true if the SwitchButton is empty, false otherwise.

public boolean isEmptyIgnoreSpaces()
Checks if the SwitchButton is empty, ignoring spaces.

Returns:

true if the SwitchButton is empty, false otherwise.

public String getStringValue()
Gets the value of the SwitchButton as a string.

Returns:

a string representation of the Boolean value.

public SwitchButton grow()
Adds a CSS class to make the SwitchButton grow in size.

Returns:

the current instance of SwitchButton .

public SwitchButton ungrow()
Removes the CSS class that makes the SwitchButton grow in size.

Returns:

the current instance of SwitchButton .

public SwitchButton grow(boolean grow)
Adds or removes the CSS class to make the SwitchButton grow in size based on the provided boolean.

grow

true to add the CSS class and make the SwitchButton grow, false to remove it.



Returns:

the current instance of SwitchButton .

public SwitchButton condenseLabels()
Adds a CSS class to condense the labels of the SwitchButton.

Returns:

the current instance of SwitchButton .

public SwitchButton uncondenseLabels()
Removes the CSS class that condenses the labels of the SwitchButton.

Returns:

the current instance of SwitchButton .

public SwitchButton condenseLabels(boolean grow)
Adds or removes the CSS class to condense the labels of the SwitchButton based on the provided boolean.

grow

true to add the CSS class and condense the labels, false to remove it.



Returns:

the current instance of SwitchButton .

public String getName()
Gets the name attribute of the SwitchButton's input element.

Returns:

the name attribute value.

public SwitchButton setName(String name)
Sets the name attribute of the SwitchButton's input element.

name

the name attribute to be set.



Returns:

the current instance of SwitchButton .

We are a group of passionate people who love what we do

Donate & Support Us