# Yahoo! UI Library

### Button 2.8.0r4

Yahoo! UI Library > button > YAHOO.widget.ButtonGroup
Search:
Filters Show Private Show Protected Show Deprecated

## Class YAHOO.widget.ButtonGroup - extends YAHOO.util.Element

The ButtonGroup class creates a set of buttons that are mutually exclusive; checking one button in the set will uncheck all others in the button group.

### Constructor

YAHOO.widget.ButtonGroup `( p_oElement , p_oAttributes )`

Parameters:
  `p_oElement <String>` String specifying the id attribute of the `<div>` element of the button group.
  `p_oElement <HTMLDivElement>` Object specifying the `<div>` element of the button group.
  `p_oElement <Object>` Object literal specifying a set of configuration attributes used to create the button group.
  `p_oAttributes <Object>` Optional. Object literal specifying a set of configuration attributes used to create the button group.

### Properties

#### _buttons - `protected Array`

Array of buttons in the button group.
Default Value: null

#### CLASS_NAME_PREFIX - `final String`

Prefix used for all class names applied to a ButtonGroup.
Default Value: "yui-"

#### CSS_CLASS_NAME - `final String`

String representing the CSS class(es) to be applied to the button group's element.
Default Value: "buttongroup"

#### NODE_NAME - `final String`

The name of the tag to be used for the button group's element.
Default Value: "DIV"

#### Properties inherited from YAHOO.util.Element:

`DOM_EVENTS`

#### Properties inherited from YAHOO.util.AttributeProvider:

`_configs`

### Methods

#### _createGroupElement

`protected HTMLDivElement _createGroupElement ( )`
Creates the button group's element.

Returns: `HTMLDivElement`

#### _onAppendTo

`protected void _onAppendTo ( p_oEvent )`
"appendTo" event handler for the button group.

Parameters:
  `p_oEvent <Event>` Object representing the event that was fired.

Returns: `void`

#### _onButtonCheckedChange

`protected void _onButtonCheckedChange ( p_oEvent , p_oButton )`
"checkedChange" event handler for each button in the button group.

Parameters:
  `p_oEvent <Event>` Object representing the event that was fired.
  `p_oButton <YAHOO.widget.Button>` Object representing the button that fired the event.

Returns: `void`

#### _onKeyDown

`protected void _onKeyDown ( p_oEvent )`
"keydown" event handler for the button group.

Parameters:
  `p_oEvent <Event>` Object representing the DOM event object passed back by the event utility (YAHOO.util.Event).

Returns: `void`

#### _setDisabled

`protected void _setDisabled ( p_bDisabled )`
Sets the value of the button groups's "disabled" attribute.

Parameters:
  `p_bDisabled <Boolean>` Boolean indicating the value for the button group's "disabled" attribute.

Returns: `void`

#### addButton

`YAHOO.widget.Button addButton ( p_oButton )`
Adds the button to the button group.

Parameters:
  `p_oButton <YAHOO.widget.Button>` Object reference for the YAHOO.widget.Button instance to be added to the button group.
  `p_oButton <String>` String specifying the id attribute of the `<input>` or `<span>` element to be used to create the button to be added to the button group.
  `p_oButton <HTMLInputElement|HTMLElement>` Object reference for the `<input>` or `<span>` element to be used to create the button to be added to the button group.
  `p_oButton <Object>` Object literal specifying a set of YAHOO.widget.Button configuration attributes used to configure the button to be added to the button group.

Returns: `YAHOO.widget.Button`

#### addButtons

`Array addButtons ( p_aButtons )`
Adds the array of buttons to the button group.

Parameters:
  `p_aButtons <Array>` Array of YAHOO.widget.Button instances to be added to the button group.
  `p_aButtons <Array>` Array of strings specifying the id attribute of the `<input>` or `<span>` elements to be used to create the buttons to be added to the button group.
  `p_aButtons <Array>` Array of object references for the `<input>` or `<span>` elements to be used to create the buttons to be added to the button group.
  `p_aButtons <Array>` Array of object literals, each containing a set of YAHOO.widget.Button configuration attributes used to configure each button to be added to the button group.

Returns: `Array`

#### check

`void check ( p_nIndex )`
Checks the button at the specified index.

Parameters:
  `p_nIndex <Number>` Number indicating the index of the button to check.

Returns: `void`

#### destroy

`void destroy ( )`
Removes the button group's element from its parent element and removes all event handlers.

Returns: `void`

#### focus

`void focus ( p_nIndex )`
Sets focus to the button at the specified index.

Parameters:
  `p_nIndex <Number>` Number indicating the index of the button to focus.

Returns: `void`

#### getButton

`YAHOO.widget.Button getButton ( p_nIndex )`
Returns the button at the specified index.

Parameters:
  `p_nIndex <Number>` The index of the button to retrieve from the button group.

Returns: `YAHOO.widget.Button`

#### getButtons

`Array getButtons ( )`
Returns an array of the buttons in the button group.

Returns: `Array`

#### getCount

`Number getCount ( )`
Returns the number of buttons in the button group.

Returns: `Number`

#### init

`void init ( p_oElement , p_oAttributes )`
The ButtonGroup class's initialization method.

Parameters:
  `p_oElement <String>` String specifying the id attribute of the `<div>` element of the button group.
  `p_oElement <HTMLDivElement>` Object specifying the `<div>` element of the button group.
  `p_oElement <Object>` Object literal specifying a set of configuration attributes used to create the button group.
  `p_oAttributes <Object>` Optional. Object literal specifying a set of configuration attributes used to create the button group.

Returns: `void`

#### initAttributes

`void initAttributes ( p_oAttributes )`
Initializes all of the configuration attributes used to create the button group.

Parameters:
  `p_oAttributes <Object>` Object literal specifying a set of configuration attributes used to create the button group.

Returns: `void`

#### removeButton

`void removeButton ( p_nIndex )`
Removes the button at the specified index from the button group.

Parameters:
  `p_nIndex <Number>` Number specifying the index of the button to be removed from the button group.

Returns: `void`

#### toString

`String toString ( )`
Returns a string representing the button group.

Returns: `String`

#### Methods inherited from YAHOO.util.Element:

`_setHTMLAttrConfig, addClass, addListener, appendChild, appendTo, delegate, fireQueue, getElementsByClassName, getElementsByTagName, getStyle, hasChildNodes, hasClass, initAttributes, insertBefore, on, removeChild, removeClass, removeDelegate, removeListener, replaceChild, replaceClass, setStyle, subscribe`

#### Methods inherited from YAHOO.util.AttributeProvider:

`configureAttribute, fireBeforeChangeEvent, fireChangeEvent, get, getAttributeConfig, getAttributeKeys, refresh, register, resetAttributeConfig, resetValue, set, setAttributeConfig, setAttributes`

### Events

#### beforeCheckedButtonChange

`beforeCheckedButtonChange ( event )`
Fires before the value for the configuration attribute 'checkedButton' changes. Return false to cancel the attribute change.

Parameters:
  `event <{oldValue: any, newValue: any}>` An object containing the previous attribute value and the new value.

#### beforeContainerChange

`beforeContainerChange ( event )`
Fires before the value for the configuration attribute 'container' changes. Return false to cancel the attribute change.

Parameters:
  `event <{oldValue: any, newValue: any}>` An object containing the previous attribute value and the new value.

#### beforeDisabledChange

`beforeDisabledChange ( event )`
Fires before the value for the configuration attribute 'disabled' changes. Return false to cancel the attribute change.

Parameters:
  `event <{oldValue: any, newValue: any}>` An object containing the previous attribute value and the new value.

#### beforeNameChange

`beforeNameChange ( event )`
Fires before the value for the configuration attribute 'name' changes. Return false to cancel the attribute change.

Parameters:
  `event <{oldValue: any, newValue: any}>` An object containing the previous attribute value and the new value.

#### beforeValueChange

`beforeValueChange ( event )`
Fires before the value for the configuration attribute 'value' changes. Return false to cancel the attribute change.

Parameters:
  `event <{oldValue: any, newValue: any}>` An object containing the previous attribute value and the new value.

#### checkedButtonChange

`checkedButtonChange ( event )`
Fires when the value for the configuration attribute 'checkedButton' changes.

Parameters:
  `event <{oldValue: any, newValue: any}>` An object containing the previous attribute value and the new value.

#### containerChange

`containerChange ( event )`
Fires when the value for the configuration attribute 'container' changes.

Parameters:
  `event <{oldValue: any, newValue: any}>` An object containing the previous attribute value and the new value.

#### disabledChange

`disabledChange ( event )`
Fires when the value for the configuration attribute 'disabled' changes.

Parameters:
  `event <{oldValue: any, newValue: any}>` An object containing the previous attribute value and the new value.

#### nameChange

`nameChange ( event )`
Fires when the value for the configuration attribute 'name' changes.

Parameters:
  `event <{oldValue: any, newValue: any}>` An object containing the previous attribute value and the new value.

#### valueChange

`valueChange ( event )`
Fires when the value for the configuration attribute 'value' changes.

Parameters:
  `event <{oldValue: any, newValue: any}>` An object containing the previous attribute value and the new value.

#### Events inherited from YAHOO.util.Element:

`appendTo, available, beforeAppendTo, beforeElementChange, contentReady, elementChange,`

### Configuration Attributes

#### checkedButton `- {YAHOO.widget.Button}`

Reference for the button in the button group that is checked.
Default Value: null

#### container `- writeonce HTMLElement|String`

HTML element reference or string specifying the id attribute of the HTML element that the button group's markup should be rendered into.
Default Value: null

#### disabled `- Boolean`

Boolean indicating if the button group should be disabled. Disabling the button group will disable each button in the button group. Disabled buttons are dimmed and will not respond to user input or fire events.
Default Value: false

#### name `- String`

String specifying the name for the button group. This name will be applied to each button in the button group.
Default Value: null

#### value `- Object`

Object specifying the value for the button group.
Default Value: null

#### Configuration attributes inherited from YAHOO.util.Element:

`element,`

Copyright © 2009 Yahoo! Inc. All rights reserved.