Toggle button elements
A ToggleFormElement
writes a <input type="checkbox">
tag to the output.
It shares the same functionality as the CheckboxFormElement, but uses the toggle
type instead.
For more information see the bootstrap 4 toggle switch documentation.
Element and builder
The ViewElement
implementation for a toggle switch element is a ToggleFormElement
which is a CheckboxFormElement
that specifies a different input type.
A builder can be created via the BootstrapElements.bootstrap.builders#toggle
factory methods.
Examples
Creating a toggle switch
import static com.foreach.across.modules.bootstrapui.ui.factories.BootstrapViewElements.bootstrap;
bootstrap.builders.toggle()
.build();
Providing a label
import static com.foreach.across.modules.bootstrapui.ui.factories.BootstrapViewElements.bootstrap;
bootstrap.builders.toggle()
.label( "John" ) (1)
.build()
1 | A label for a toggle switch can also be provided using the text method on the OptionFormElementBuilder .
The value set via the label method always takes precedence over the text value. |
Toggle list
import static com.foreach.across.modules.bootstrapui.ui.factories.BootstrapViewElements.bootstrap;
bootstrap.builders.toggleList()
.label( "John" )
.add( bootstrap.builders.option.option().text( "" ).value( 0 ) )
.add( bootstrap.builders.option.option().text( "option 1" ).value( 1 ) )
.build()