Checkbox elements
A CheckboxFormElement
writes a <input type="checkbox">
tag to the output.
Element and builder
The ViewElement
implementation for a checkbox element is a CheckboxFormElement
.
A builder can be created via the BootstrapViewElements.bootstrap.builders#checkbox
factory methods.
Thymeleaf model writer
A CheckboxFormElementWriter
writes <input>
tags to the Thymeleaf model.
Based on the configuration of the CheckboxFormElement
that should be written, child elements will be added or attributes will be provided to the tag.
If it holds text or child elements, a label will be added.
Examples
Creating a checkbox
import static com.foreach.across.modules.bootstrapui.ui.factories.BootstrapViewElements.bootstrap;
bootstrap.builders.checkbox()
.build();
Providing a label
import static com.foreach.across.modules.bootstrapui.ui.factories.BootstrapViewElements.bootstrap;
bootstrap.builders.checkbox()
.label( "John" ) (1)
.build()
1 | A label for a checkbox button 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. |
Not wrapping a checkbox
Checkbox elements are wrapped inside a div
by default.
By specifying the wrapped
property on a CheckboxFormElement
, this behaviour can be prevented.
If a checkbox element is not wrapped, it will be rendered within the label if one is present.
import static com.foreach.across.modules.bootstrapui.ui.factories.BootstrapViewElements.bootstrap;
bootstrap.builders.checkbox()
.label( "John" )
.wrapped( false )
.build()
Multi checkbox
import static com.foreach.across.modules.bootstrapui.ui.factories.BootstrapViewElements.bootstrap;
bootstrap.builders.checkboxList()
.label( "John" )
.add( bootstrap.builders.option.option().text( "" ).value( 0 ) )
.add( bootstrap.builders.option.option().text( "option 1" ).value( 1 ) )
.build()