Select elements

A SelectFormElement writes a <select> tag to the output. For more information about the OptionsFormElementBuilder see the options section.

Element and builder

The SelectFormElement implementation has an equivalent OptionsFormElementBuilder. A builder can be created using the BootstrapElements.bootstrap.builders.select() factory method.

Examples

Single select

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

bootstrap.builders.select()
  .controlName( "controlName" )
  .name( "internalName" )
  .readonly( false )
  .add( bootstrap.builders.select.option().value( "one" ).text( "Inner text" ) )
  .add( bootstrap.builders.select.option().value( "twoe" ).text( "Second text" ) )
  .build();

Multiple select with optionGroups

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

SelectFormElement.OptionGroup group = new SelectFormElement.OptionGroup();
group.setLabel( "Group label" );
group.addChild(bootstrap.builders.select.option().value( "two" ).text( "Inner text 2" ).build());
group.addChild(bootstrap.builders.select.option()value( "Short two" )text( "Some text" ).build());

return bootstrap.builders.select()
  .add( group )
  .multiple( true )
  .controlName( "controlName" )
  .name( "internalName" )
  .readonly( false )
  .build();

Bootstrap-Select

If you want to create a more advanced bootstrap-select dropdown instead of a simple HTML select, you can do so by specifying a SelectFormElementConfiguration object. See the respective javadoc for all configuration properties.

Message codes

The SelectFormElementConfiguration allows you to configure the default text for the control. These properties support message code text snippets which will be replaced if a SelectFormElement is built using the OptionsFormElementBuilder.

The following default message codes are used:

Property Message code Default text

selectAllText

BootstrapUiModule.SelectFormElementConfiguration.selectAllText

Select all

noneSelectedText

BootstrapUiModule.SelectFormElementConfiguration.noneSelectedText

Nothing selected

maxOptionsText

BootstrapUiModule.SelectFormElementConfiguration.maxOptionsText

Limit reached ({0} items max)

countSelectedText

BootstrapUiModule.SelectFormElementConfiguration.countSelectedText

{0} items selected

deselectAllText

BootstrapUiModule.SelectFormElementConfiguration.countSelectedText

Deselect all

Message code replacement is performed when SelectFormElementConfiguration.localize() is called. This is done automatically when using an OptionsFormElementBuilder.
import static com.foreach.across.modules.bootstrapui.ui.factories.BootstrapViewElements.bootstrap;

bootstrap.builders
    .select( SelectFormElementConfiguration.simple())
    .multiple()
    .controlName( "boxName" )
    .add( bootstrap.builders.select.option().label( "Orange" ).value( "orange" ) )
    .add( bootstrap.builders.select.option().label( "Apple" ).value( "apple" ) )
    .build();