Label Elements

A LabelFormElement writes a <label> tag to the output.

Element and builder

The ViewElement implementation for a label element is a LabelFormElement and has a corresponding LabelFormElementBuilder. A LabelFormElement can also be created via the BootstrapViewElements.bootstrap.builders#label factory methods.

Examples

Creating a LabelFormElement

import static com.foreach.across.modules.bootstrapui.ui.factories.BootstrapViewElements.bootstrap;

bootstrap.builders.label("Author")
                   .build();

Target element

A label can also have a target element. This ensures that the elements are correctly associated by providing a for attribute. In the following example, we’ll also create a textbox element to refer to.

import static com.foreach.across.modules.bootstrapui.ui.factories.BootstrapViewElements.bootstrap;

ViewElement author = bootstrap.builders.textbox()
                                        .htmlId( "author" )
                                        .build();
bootstrap.builders.label("Author")
                   .target(authorControl);

Child elements

Label elements can also have other ViewElement s as their children. These will also be rendered inside the body of the label element. Let’s for example add an icon element to the label.

import static com.foreach.across.modules.bootstrapui.ui.factories.BootstrapViewElements.bootstrap;

bootstrap.builders.label( "Author" )
		           .add( IconSet.iconSet( FONT_AWESOME_BRANDS_ICON_SET ).icon( "apple" ) )
		           .build();