Initializer
.ojButtonset(options)
option()
.
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
options |
Object |
<optional> |
a map of option-value pairs to set on the component |
- Source:
- ojbutton/ojbutton.js, line 1303
Examples
Initialize the buttonset with no options specified:
$( ".selector" ).ojButtonset();
Initialize the buttonset with some options and callbacks specified:
$( ".selector" ).ojButtonset( { "disabled": true, "create": function( event, ui ) {} } );
Initialize the buttonset via the JET ojComponent
binding:
<div id="beverages" data-bind="ojComponent: { component: 'ojButtonset',
disabled: true,
create: setupButtonset }">
Options
-
#checked :string|Array.<string>|undefined
-
The
checked
option indicates which radio or checkboxes in the Buttonset are selected. It corresponds to thevalue
attribute of those elements, which should always be set.If this Buttonset consists of a single radio group, and no other buttons, then
checked
is a string equal to thevalue
attribute of the checked radio. The option isnull
if and only if no radio is selected. Thus, an n-radio group has n+1 validchecked
values: the n radio values, andnull
.If this Buttonset consists of one or more checkboxes, and no other buttons, then
checked
is a possibly empty, non-null
string array containing thevalue
attributes of the checked checkboxes. This array has "set", not "list", semantics; i.e. order is neither important nor guaranteed. Thus, an n-checkbox set has 2^n validchecked
values: the 2^n possible subsets of n checkboxes.In all other cases,
checked
isnull
.After create time, the
checked
state should be set via this API, not by setting the underlying DOM attribute.The 2-way
checked
binding offered by theojComponent
binding should be used instead of Knockout's built-inchecked
binding, as the former sets the API, while the latter sets the underlying DOM attribute.An
optionChange
event is fired whenever this option changes, whether due to user interaction or programmatic intervention. If the value is the same as the previous value (using order-independent "set" equality for checkboxes), no event will be fired.Often there is no need to listen for this event, since the
ojComponent
checked
binding, discussed above, will update the bound observable whenever thechecked
state changes.- Default Value:
- If not initially set, is initialized to reflect the initial DOM state
- Source:
- ojbutton/ojbutton.js, line 1526
Examples
Initialize a buttonset with the
checked
option specified:// radio $( ".selector" ).ojButtonset( { "checked": "tea" } ); // checkbox $( ".selector" ).ojButtonset( { "checked": ["bold", "italic"] } );
Get or set the
checked
option, after initialization:// getter var display = $( ".selector" ).ojButtonset( "option", "checked" ); // radio setter $( ".selector" ).ojButtonset( "option", "checked", "tea" ); // checkbox setter $( ".selector" ).ojButtonset( "option", "checked", ["bold", "italic"] );
-
#contextMenu :Object
-
JQ selector identifying the JET Menu that the component should launch as a context menu on right-click or Shift-F10. If specified, the browser's native context menu will be replaced by the specified JET Menu.
To specify a JET context menu on a DOM element that is not a JET component, see the
ojContextMenu
binding.To make the page semantically accurate from the outset, applications are encouraged to specify the context menu via the standard HTML5 syntax shown in the below example. When the component is initialized, the context menu thus specified will be set on the component.
The JET Menu should be initialized before any component using it as a context menu.
- Default Value:
null
- Inherited From:
- Source:
- ojcomponentcore/jqueryui-base.js, line 51
Examples
Initialize a JET component with a context menu:
// via recommended HTML5 syntax: <div id="myComponent" contextmenu="myMenu" data-bind="ojComponent: { ... }> // via JET initializer (less preferred) : $( ".selector" ).ojFoo({ "contextMenu": "#myMenu" });
Get or set the
contextMenu
option, after initialization:// getter var menu = $( ".selector" ).ojFoo( "option", "contextMenu" ); // setter $( ".selector" ).ojFoo( "option", "contextMenu", ".my-marker-class" );
Set a JET context menu on an ordinary HTML element:
<a href="#" id="myAnchor" contextmenu="myMenu" data-bind="ojContextMenu: {}">Some text
-
#disabled :boolean
-
If the
disabled
option is set totrue
at create time, then all its buttons will be disabled. If it isfalse
at create time, then each button'sdisabled
status will be set from the button's API and DOM in the same way as a standalone JET Button.Setting the
disabled
option after creation will enable or disable all contained buttons. Enabling or disabling the individual buttons will not update the value of Buttonset'sdisabled
option.- Default Value:
false
- Source:
- ojbutton/ojbutton.js, line 1529
Examples
Initialize the buttonset with the
disabled
option specified:$( ".selector" ).ojButtonset( { "disabled": true } );
Get or set the
disabled
option, after initialization:// getter (does not reflect changes made directly to the buttons) var disabled = $( ".selector" ).ojButtonset( "option", "disabled" ); // setter $( ".selector" ).ojButtonset( "option", "disabled", true );
-
#focusManagement :string
-
The
focusManagement
option should be set to"none"
when the Buttonset is placed in a JET Toolbar. This allows the Toolbar to manage the focus with no interference from the Buttonset, so that arrow keys move within the entire Toolbar, not just within the Buttonset.- Default Value:
"oneTabstop"
- Source:
- ojbutton/ojbutton.js, line 1580
Supported Values:
Name Type Description "oneTabstop"
string Focus management is enabled. The Buttonset is a single tabstop with arrow-key navigation. "none"
string Focus management is disabled, to avoid interfering with the focus management of a containing component. Examples
Initialize the buttonset with the
focusManagement
option specified:$( ".selector" ).ojButtonset( { "focusManagement": "none" } );
Get or set the
focusManagement
option, after initialization:// getter var display = $( ".selector" ).ojButtonset( "option", "focusManagement" ); // setter $( ".selector" ).ojButtonset( "option", "focusManagement", "none" );
-
#rootAttributes :Object|undefined
-
Attributes specified here will be set on the component's root DOM element at creation time. This is particularly useful for components like Dialog that wrap themselves in a root element at creation time.
The specified
class
andstyle
are appended to the current class and style, respectively. All other attributes overwrite any existing value.Setting this option after component creation has no effect.
- Default Value:
undefined
- Inherited From:
- Source:
- ojcomponentcore/jqueryui-base.js, line 77
Example
Initialize a JET component, specifying a set of attributes to be set on the component's root DOM element:
$( ".selector" ).ojFoo({ "rootAttributes": { 'id': 'myId', 'style': 'max-width:100%; color:blue;', 'class': 'my-class' }});
Events
-
#create
-
Triggered when the buttonset is created.
- Source:
- ojbutton/ojbutton.js, line 1621
Properties:
Name Type Description event
Event jQuery
event objectui
Object Empty object included for consistency with other events Examples
Initialize the buttonset with the
create
callback specified:$( ".selector" ).ojButtonset({ "create": function( event, ui ) {} });
Bind an event listener to the
ojcreate
event:$( ".selector" ).on( "ojcreate", function( event, ui ) {} );
-
#optionChange
-
Fired whenever a supported component option changes, whether due to user interaction or programmatic intervention. If the new value is the same as the previous value, no event will be fired.
Currently there is one supported option,
checked
. Additional options may be supported in the future, so listeners should verify which option is changing before taking any action.Often there is no need to listen for this event, since the 2-way
checked
binding offered by theojComponent
binding will update the bound observable whenever thechecked
state changes.- Source:
- ojbutton/ojbutton.js, line 1619
Properties:
Name Type Description event
Event jQuery
event objectui
Object Parameters Properties
Name Type Argument Description option
string the name of the option that is changing previousValue
string | Array.<string> <nullable>
the previous value of the option. null
iff the previous value wasnull
.value
string | Array.<string> <nullable>
the current value of the option. null
iff the current value isnull
.optionMetadata
Object information about the option that is changing Properties
Name Type Description writeback
string "shouldWrite"
or"shouldNotWrite"
. For use by the JET writeback mechanism.Examples
Initialize the buttonset with the
optionChange
callback specified:$( ".selector" ).ojButtonset({ "optionChange": function( event, ui ) {} });
Bind an event listener to the
ojoptionchange
event:$( ".selector" ).on( "ojoptionchange", function( event, ui ) {} );
Methods
-
#destroy()
-
Removes the buttonset functionality completely, including focus management, and recursively
destroy()
s the contained buttons. This will return the element back to its pre-init state.This method does not accept any arguments.
- Source:
- ojbutton/ojbutton.js, line 2240
Returns:
When called via the public jQuery syntax, this method returns the object on which it was called, to facilitate method chaining.Example
Invoke the
destroy
method:$( ".selector" ).ojButtonset( "destroy" );
-
#getNodeBySubId(locator) → {Element|null}
-
Return the subcomponent node represented by the documented locator attribute values.
Parameters:
Name Type Description locator
Object An Object containing at minimum a subId property whose value is a string, documented by the component, that allows the component to look up the subcomponent associated with that string. It contains: component: optional component name - in the future there may be more than one component contained within a page element
subId: the string, documented by the component, that the component expects in getNodeBySubId to locate a particular subcomponent.
- Inherited From:
- Source:
- ojcomponentcore/jqueryui-base.js, line 526
Returns:
the subcomponent located by the subId string passed in locator, if found.- Type
- Element | null
-
#getSubIdByNode(node) → {string|null}
-
Return the subId string for the given child DOM node
Parameters:
Name Type Description node
Element child DOM node - Inherited From:
- Source:
- ojcomponentcore/jqueryui-base.js, line 548
Returns:
- the subId for the DOM node or null when none is found- Type
- string | null
-
#option(optionName, value) → {Object|undefined}
-
This method has several overloads, which gets and set component options.
The first overload accepts a single
optionName
param as a string, and returns the current value of that option.The second overload accepts two params, an
optionName
string and a new value to which that option will be set.The third overload accepts no params, and returns a map of key/value pairs representing all the component options and their values.
The fourth overload accepts a single map of option-value pairs to set on the component.
Parameters:
Name Type Argument Description optionName
string | Object <optional>
the option name (string, first two overloads), or the map (Object, last overload). Omitted in the third overload. value
Object <optional>
a value to set for the option. Second overload only. - Inherited From:
- Source:
- ojcomponentcore/jqueryui-base.js, line 600
Returns:
The getter overloads return the retrieved value(s). When called via the public jQuery syntax, the setter overloads return the object on which they were called, to facilitate method chaining.- Type
- Object | undefined
Examples
First overload: get one option:
var isDisabled = $( ".selector" ).ojFoo( "option", "disabled" ); // Foo is Button, Menu, etc.
Second overload: set one option:
$( ".selector" ).ojFoo( "option", "disabled", true ); // Foo is Button, Menu, etc.
Third overload: get all options:
var options = $( ".selector" ).ojFoo( "option" ); // Foo is Button, Menu, etc.
Fourth overload: set one or more options:
$( ".selector" ).ojFoo( "option", { disabled: true } ); // Foo is Button, Menu, etc.
-
#refresh()
-
Refreshes the buttonset, including the following:
- Creates JET Buttons out of all contained DOM elements supported by JET Button that are not already Buttons, by calling
.ojButton()
on them. - Re-applies focus management / keyboard navigation.
- Applies special styles to the first and last button of the buttonset (e.g. for rounded corners, depending on theming).
- Rechecks the reading direction (LTR vs. RTL).
A
refresh()
is required in the following circumstances:- After buttons are added to or removed from the buttonset.
- After a change to the
disabled
status of any of the buttons in the buttonset. - After the reading direction (LTR vs. RTL) changes.
This method does not accept any arguments.
- Source:
- ojbutton/ojbutton.js, line 1914
Returns:
When called via the public jQuery syntax, this method returns the object on which it was called, to facilitate method chaining.Example
Invoke the
refresh
method:$( ".selector" ).ojButtonset( "refresh" );
- Creates JET Buttons out of all contained DOM elements supported by JET Button that are not already Buttons, by calling
-
#widget() → {jQuery}
-
Returns a
jQuery
object containing the buttonset element.This method does not accept any arguments.
- Source:
- ojbutton/ojbutton.js, line 2238
Returns:
the buttonset element- Type
- jQuery
Example
Invoke the
widget
method:var widget = $( ".selector" ).ojButtonset( "widget" );
Non-public Methods
Note: Extending JET components is not currently supported. Thus, non-public methods are for internal use only.
-
<protected> #_AfterCreate()
-
This method is called after
_ComponentCreate
. The JET base component does tasks here that must happen after the component (subclass) has created itself in its override of_ComponentCreate
. Notably, the base component handles therootAttributes
andcontextMenu
options here, since those options operate on the component root node, which for some components is created in their override of_ComponentCreate
.Subclasses should override this method only if they have tasks that must happen after a superclass's implementation of this method, e.g. tasks that must happen after the context menu is set on the component.
Overrides of this method should call
this._super
first.- Inherited From:
- Source:
- ojcomponentcore/jqueryui-base.js, line 292
Returns:
When called via the public jQuery syntax, this method returns the object on which it was called, to facilitate method chaining. -
<protected> #_ComponentCreate()
-
All component create-time initialization lives in this method, except the logic that specifically needs to live in
_InitOptions
or_AfterCreate
, per the documentation for those methods. All DOM creation must happen here, since the intent of_AfterCreate
is to contain superclass logic that must run after that DOM is created.Overrides of this method should call
this._super
first.- Inherited From:
- Source:
- ojcomponentcore/jqueryui-base.js, line 266
Returns:
When called via the public jQuery syntax, this method returns the object on which it was called, to facilitate method chaining. -
<protected> #_GetReadingDirection() → {string}
-
Determines whether the component is LTR or RTL.
Component responsibilities:
- All components must determine directionality exclusively by calling this protected superclass method. (So that any future updates to the logic can be made in this one place.)
- Components that need to know the directionality must call this method from
_create()
andrefresh()
, and cache the value. - Components should not call this at other times, and should instead use the cached value. (This avoids constant DOM queries, and avoids any future issues if directional islands and component reparenting (e.g. popups) should coexist.)
App responsibilities:
- The app specifies directionality by setting the HTML
"dir"
attribute on the<html>
node. When omitted, the default is"ltr"
. (Per-component directionality / directional islands are not currently supported due to inadequate CSS support.) - As with any DOM change, the app must
refresh()
the component if the directionality changes dynamically. (This provides a hook for component housekeeping, and allows caching.)
- Default Value:
"ltr"
- Inherited From:
- Source:
- ojcomponentcore/jqueryui-base.js, line 888
Returns:
the reading direction, either"ltr"
or"rtl"
- Type
- string
-
<protected> #_GetSavedAttributes(element) → {Object}
-
Gets the saved attributes for the provided element. This is usually the original list of attributes set on the element.
Parameters:
Name Type Description element
Object jQuery selection, should be a single entry - Inherited From:
- Source:
- ojcomponentcore/jqueryui-base.js, line 359
Returns:
savedAttributes - attributes that were saved for this element.- Type
- Object
-
<protected> #_InitOptions()
-
This method is called before
_ComponentCreate
, at which point the component has not yet been rendered. Component options should be initialized in this method, so that their final values are in place when_ComponentCreate
is called.This includes getting option values from the DOM, where applicable, and coercing option values (however derived) to their appropriate data type. No other work should be done in this method. See below for details.
Overrides of this method should call
this._super
first.Usage:
- If the component has an option like
disabled
that can be set from the DOM at create time, then the "get from DOM" logic should live in this method. E.g. a typical override might say "if thedisabled
option still has its initial value ofundefined
(i.e., the option has not been set), then get the DOM property and set it on the option." (See also next bullet.) - For attributes that live on the component's root node, keep in mind that anything specified via
the
rootAttributes
option will not be placed on the DOM until_AfterCreate
. So when getting attributes from the root node, components must first look in therootAttributes
option, and then, only if the attribute is not found there, look on the component root (if it already exists). - For options that, unlike
disabled
, have no corresponding DOM property, and are not otherwise set from the DOM, there is nothing to do in this method. - Do NOT set anything on the DOM in this method (like the resolved
disabled
value, or anyrootAttributes
values). The resolved option values should be set on the DOM later, in_ComponentCreate
, and therootAttributes
values are set inbaseComponent._AfterCreate
.
- Inherited From:
- Source:
- ojcomponentcore/jqueryui-base.js, line 249
Returns:
When called via the public jQuery syntax, this method returns the object on which it was called, to facilitate method chaining. - If the component has an option like
-
<protected> #_RestoreAttributes()
-
Restores the saved element's attributes
- Inherited From:
- Source:
- ojcomponentcore/jqueryui-base.js, line 385
Returns:
When called via the public jQuery syntax, this method returns the object on which it was called, to facilitate method chaining. -
<protected> #_SaveAttributes(element)
-
Saves the element's attributes within an internal variable to be reset during the destroy function The JSON variable will be held as : [ { "element" : element[i], "attributes" : { attributes[m]["name"] : {"attr": attributes[m]["value"], "prop": $(element[i]).prop(attributes[m]["name"]) } } ]
Parameters:
Name Type Description element
Object jQuery selection to save attributes for - Inherited From:
- Source:
- ojcomponentcore/jqueryui-base.js, line 320
Returns:
When called via the public jQuery syntax, this method returns the object on which it was called, to facilitate method chaining. -
<protected> #_SetRootAttributes()
-
Reads the
rootAttributes
option, and sets the root attributes on the component's root DOM element.class
andstyle
are appended to the current class and style, respectively. All other attributes overwrite any existing value.- Inherited From:
- Source:
- ojcomponentcore/jqueryui-base.js, line 103
Returns:
When called via the public jQuery syntax, this method returns the object on which it was called, to facilitate method chaining.