Form groups encapsulate components related to a single form input. At a minimum, it should contain ControLabel
and FormControl
child components. Many FormGroup
properties will be transformed or passed along to its children so these values will not need to be manually re-specified.
NOTE: Checkbox
controls are not allowed inside FormGroup
as they are self-labeling.
NOTE: Form groups have no explict width so they rely on the size of their child components. Starting in Version 12, any child component with a .form-control
class (FormControl
, Dropdown
, TextArea
, Password
) will have its width set to 100%. Because of that, form groups should be laid out on the page in sized containers (e.g. columns) to avoid them spanning the entire width of the window.
Three sizes are supported: 'lg'
(the default), 'md'
and 'sm'
. Use the size
property to set the size.
Note the use of the FormGroup.HelpBlock
component to provide additional explanatory text in the following example.
Use the readOnly
property to mark form controls as readonly. Input controls will have the readonly
attribute set so that they can receive focus, to support keyboard-only navigation and other assistive technologies.
Notes:
readOnly
and required
properties. This will throw a PropType validation error because readonly
form controls are barred from any kind of constraint validation.readOnly
and validationMessage
properties. This will throw a PropType validation error because readonly
form controls are barred from any kind of constraint validation.readOnly
on a form group when the underlying form control is a Dropdown. This will throw a PropType validation error because the <select>
element cannot have readonly
set.Use the required
property to mark form controls as required. Labels will display a visual indication while input controls will have a required
attribute added to help with assistive technologies.
Validation state properties apply only to FormGroup
components (not individual ControlLabel
or FormControl
components). The validation tooltip will be triggered when hovering over the icon next to the ControlLabel
and also when the FormControl
receives focus. Use the validationMessage
property to set a validation state.
Use the validationMessageType
property to change how the validation message will display if one is present. The validation message will display 'iconAligned'
by default like the above example in validation states. By selecting 'inputAligned'
, the validation message will display as an overlay underneath the input.
Property | Type | Default | Description |
---|---|---|---|
children | Node | Collection of React components to be placed in the form group (ControlLabel , FormControl , FormGroup.HelpBlock ). | |
className | String | Custom classes to be added to the <div> tag. | |
controlId | String | Sets id attribute on FormControl and htmlFor property on ControlLabel . | |
disabled | Boolean | false | Will pass the disabled property to child components that support disabled. |
disableFullWidth | Boolean | false | Sets the child’s input width to auto instead of 100% . |
formGroupRef | Ref or Function | Attaches a ref to the wrapping <div> tag. | |
readOnly | Boolean | false | Will pass the readonly property to input controls. Please use in compliance with these usage notes. |
required | Boolean | false | Will pass the required property to all child components (labels and input controls). |
size | String | 'lg' | Size of child elements within the form group (ControlLabel , FormControl , FormGroup.HelpBlock ). Options are 'lg' , 'md' , 'sm' . |
validationMessage | Object | An object identifying a validation message. The object will include properties for state and text ; e.g., { state: 'warning', text: 'This is your last warning' } . The options for state are 'error' and 'warning' . text is the message shown in the validation tooltip; as with all text, it must be localized. | |
validationMessageType | String | 'iconAligned' | This will determine how the validation message will appear. Options are 'iconAligned' , a tooltip from the warning or error icon, or 'inputAligned' , an overlay displaying underneath the input. |