Controlgroup Widgetversion added: 1.3
Description: Groups buttons together.
Occasionally, you may want to visually group a set of buttons to form a single block that looks contained like a navigation component. To get this effect, wrap a set of buttons in a container with the data-role="controlgroup" attribute — the framework will create a vertical button group, remove all margins and drop shadows between the buttons, and only round the first and last buttons of the set to create the effect that they are grouped together.
|
1
2
3
4
5
|
|
This will result in the following button group:
By adding the data-type="horizontal" attribute to the controlgroup container, you can swap to a horizontal-style group that floats the buttons side-by-side and sets the width to only be large enough to fit the content. (Be aware that these will wrap to multiple lines if the number of buttons or the overall text length is too wide for the screen.)
Horizontal grouped buttons:
Labels
If you use a controlgroup for input, button or select buttons we recommend wrapping them in a fieldset element that has a legend which acts as the combined label for the group. The label elements of each individual button in the group will be hidden for styling purposes, and are only accessible by screen readers. Using the label as a wrapper around the form element prevents the framework from hiding it, so you have to use the for attribute to associate the label with the input.
Options
corners
true
Sets whether to draw the controlgroup with rounded corners.
This option is also exposed as a data attribute: data-corners="false".
Initialize the controlgroup with the corners option specified:
|
1
2
3
|
|
Get or set the corners option, after initialization:
|
1
2
3
4
5
|
|
defaults
false
true indicates that other widgets options have default values and causes jQuery Mobile's widget autoenhancement code to omit the step where it retrieves option values from data attributes. This can improve startup time.
This option is also exposed as a data attribute: data-defaults="true".
Initialize the controlgroup with the defaults option specified:
|
1
2
3
|
|
Get or set the defaults option, after initialization:
|
1
2
3
4
5
|
|
disabled
false
true.
This option is also exposed as a data attribute: data-disabled="true".
Initialize the controlgroup with the disabled option specified:
|
1
2
3
|
|
Get or set the disabled option, after initialization:
|
1
2
3
4
5
|
|
excludeInvisible
true
Sets whether to exclude invisible children in the assignment of rounded corners.
When set to false, all children of a controlgroup are taken into account when assigning rounded corners, including hidden children. Thus, if, for example, the controlgroup's first child is hidden, the controlgroup will, in effect, not have rounded corners on the top edge.
This option is also exposed as a data attribute: data-exclude-invisible="false".
Initialize the controlgroup with the excludeInvisible option specified:
|
1
2
3
|
|
Get or set the excludeInvisible option, after initialization:
|
1
2
3
4
5
|
|
initSelector
See below
The default initSelector for the controlgroup widget is:
|
1
|
|
Note: This option is deprecated in 1.4.0 and will be removed in 1.5.0.
As of jQuery Mobile 1.4.0, the initSelector is no longer a widget option. Instead, it is declared directly on the widget prototype. Thus, you may specify a custom value by handling the mobileinit event and overwriting the initSelector on the prototype:
|
1
2
3
|
|
Note: Remember to attach the mobileinit handler after you have loaded jQuery, but before you load jQuery Mobile, because the event is triggered as part of jQuery Mobile's loading process.
The value of this option is a jQuery selector string. The framework selects elements based on the value of this option and instantiates controlgroup widgets on each of the resulting list of elements.
(version deprecated: 1.4.0)mini
null (false)
true, this will display a more compact version of the controlgroup that uses less vertical height by applying the ui-mini class to the outermost element of the controlgroup widget.
This option is also exposed as a data attribute: data-mini="true".
shadow
false
Sets whether a drop shadow is drawn around the controlgroup.
This option is also exposed as a data attribute: data-shadow="false".
Initialize the controlgroup with the shadow option specified:
|
1
2
3
|
|
Get or set the shadow option, after initialization:
|
1
2
3
4
5
|
|
theme
null, inherited from parent
Possible values: swatch letter (a-z).
This option is also exposed as a data attribute: data-theme="b".
Initialize the controlgroup with the theme option specified:
|
1
2
3
|
|
Get or set the theme option, after initialization:
|
1
2
3
4
5
|
|
type
vertical
Sets whether children should be stacked on top of each other or next to each other. If set to "horizontal", the children of the controlgroup will be stacked next to each other.
This option is also exposed as a data attribute: data-type="horizontal".
Initialize the controlgroup with the type option specified:
|
1
2
3
|
|
Get or set the type option, after initialization:
|
1
2
3
4
5
|
|
Methods
container()Returns: jQuery (plugin only)
|
1
|
|
- This method does not accept any arguments.
Invoke the container method:
|
1
|
|
destroy()Returns: jQuery (plugin only)
- This method does not accept any arguments.
Invoke the destroy method:
|
1
|
|
disable()Returns: jQuery (plugin only)
- This method does not accept any arguments.
Invoke the disable method:
|
1
|
|
enable()Returns: jQuery (plugin only)
- This method does not accept any arguments.
Invoke the enable method:
|
1
|
|
option( optionName )Returns: Object
optionName.-
optionNameType: StringThe name of the option to get.
Invoke the method:
|
1
|
|
option()Returns: PlainObject
- This signature does not accept any arguments.
Invoke the method:
|
1
|
|
option( optionName, value )Returns: jQuery (plugin only)
optionName.-
optionNameType: StringThe name of the option to set.
-
valueType: ObjectA value to set for the option.
Invoke the method:
|
1
|
|
option( options )Returns: jQuery (plugin only)
-
optionsType: ObjectA map of option-value pairs to set.
Invoke the method:
|
1
|
|
Events
create( event, ui )Type: controlgroupcreate
Note: The ui object is empty but included for consistency with other events.
Initialize the controlgroup with the create callback specified:
|
1
2
3
|
|
Bind an event listener to the controlgroupcreate event:
|
1
|
|
Example:
A basic example of a controlgroup.
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
|