WidgetParent Class
Widget extension providing functionality enabling a Widget to be a parent of another Widget.
In addition to the set of attributes supported by WidgetParent, the constructor
configuration object can also contain a children
which can be used
to add child widgets to the parent during construction. The children
property is an array of either child widget instances or child widget configuration
objects, and is sugar for the add method. See the
add for details on the structure of the child widget
configuration object.
Constructor
Item Index
Methods
- add
- deselectAll
- destructor
- each
- filter deprecated
- indexOf
- isEmpty
- item
- itemsAreEqual deprecated
- remove
- removeAll
- selectAll
- selectChild
- size
- some
- toJSON
Properties
Attributes
Events
Methods
add
-
child
-
index
Adds a Widget as a child. If the specified Widget already has a parent it will be removed from its current parent before being added as a child.
Parameters:
-
child
Widget | Object | ArrayThe Widget instance, or configuration object for the Widget, or Array of Widget instances to be added as a child. The configuration object for the child can include a
childType
property, which is either a constructor function or a string which names a constructor function on the Y instance (e.g. "Tab" would refer to Y.Tab).childType
used to be namedtype
, support for which has been deprecated, but is still maintained for backward compatibility.childType
takes precedence overtype
if both are defined. -
index
NumberNumber representing the position at which the child should be inserted.
Returns:
Y.ArrayList containing the successfully added Widget instance(s). If no children where added, will return an empty Y.ArrayList instance.
deselectAll
()
Deselects all children.
destructor
()
The destructor implementation for Parent widgets. Destroys all children.
each
-
fn
-
context
Execute a function on each item of the list, optionally providing a custom execution context. Default context is the item.
The callback signature is callback( item, index )
.
Parameters:
-
fn
Functionthe function to execute
-
context
Mixedoptional override 'this' in the function
Returns:
this instance
filter
-
validator
Create a new ArrayList (or augmenting class instance) from a subset of items as determined by the boolean function passed as the argument. The original ArrayList is unchanged.
The validator signature is validator( item )
.
Parameters:
-
validator
FunctionBoolean function to determine in or out.
Returns:
New instance based on who passed the validator.
indexOf
-
needle
Finds the first index of the needle in the managed array of items.
Parameters:
-
needle
MixedThe item to search for
Returns:
Array index if found. Otherwise -1
isEmpty
()
Boolean
Is this instance managing any items?
Returns:
true if 1 or more items are being managed
item
-
i
Get an item by index from the list. Override this method if managing a list of objects that have a different public representation (e.g. Node instances vs DOM nodes). The iteration methods that accept a user function will use this method for access list items for operation.
Parameters:
-
i
Integerindex to fetch
Returns:
the item at the requested index
itemsAreEqual
-
a
-
b
Default comparator for items stored in this list. Used by remove().
Parameters:
-
a
Mixeditem to test equivalence with.
-
b
Mixedother item to test equivalance.
Returns:
true if items are deemed equivalent.
remove
-
index
Removes the Widget from its parent. Optionally, can remove a child by specifying its index.
Parameters:
-
index
Number(Optional.) Number representing the index of the child to be removed.
Returns:
Widget instance that was successfully removed, otherwise undefined.
removeAll
()
ArrayList
Removes all of the children from the Widget.
Returns:
Y.ArrayList instance containing Widgets that were successfully removed. If no children where removed, will return an empty Y.ArrayList instance.
selectAll
()
Selects all children.
selectChild
-
i
Selects the child at the given index (zero-based).
Parameters:
-
i
Numberthe index of the child to be selected
size
()
Integer
How many items are in this list?
Returns:
Number of items in the list
some
-
fn
-
context
Execute a function on each item of the list, optionally providing a custom execution context. Default context is the item.
The callback signature is callback( item, index )
.
Unlike each
, if the callback returns true, the
iteration will stop.
Parameters:
-
fn
Functionthe function to execute
-
context
Mixedoptional override 'this' in the function
Returns:
True if the function returned true on an item
Properties
Attributes
activeDescendant
Widget
readonly
Returns the Widget's currently focused descendant Widget.
Fires event activeDescendantChange
Fires when the value for the configuration attribute activeDescendant
is
changed. You can listen for the event using the on
method if you
wish to be notified before the attribute's value has changed, or
using the after
method if you wish to be notified after the
attribute's value has changed.
Parameters:
-
e
EventFacadeAn Event Facade object with the following attribute-specific properties added:
defaultChildType
String | Object
String representing the default type of the children managed by this Widget. Can also supply default type as a constructor reference.
Fires event defaultChildTypeChange
Fires when the value for the configuration attribute defaultChildType
is
changed. You can listen for the event using the on
method if you
wish to be notified before the attribute's value has changed, or
using the after
method if you wish to be notified after the
attribute's value has changed.
Parameters:
-
e
EventFacadeAn Event Facade object with the following attribute-specific properties added:
multiple
Boolean
Boolean indicating if multiple children can be selected at
once. Whether or not multiple selection is enabled is always delegated
to the value of the multiple
attribute of the root widget
in the object hierarchy.
Default: false
Fires event multipleChange
Fires when the value for the configuration attribute multiple
is
changed. You can listen for the event using the on
method if you
wish to be notified before the attribute's value has changed, or
using the after
method if you wish to be notified after the
attribute's value has changed.
Parameters:
-
e
EventFacadeAn Event Facade object with the following attribute-specific properties added:
selection
ArrayList | Widget
readonly
Returns the currently selected child Widget. If the
mulitple
attribte is set to true
will
return an Y.ArrayList instance containing the currently selected
children. If no children are selected, will return null.
Fires event selectionChange
Fires when the value for the configuration attribute selection
is
changed. You can listen for the event using the on
method if you
wish to be notified before the attribute's value has changed, or
using the after
method if you wish to be notified after the
attribute's value has changed.
Parameters:
-
e
EventFacadeAn Event Facade object with the following attribute-specific properties added:
Events
addChild
Fires when a Widget is add as a child. The event object will have a 'child' property that returns a reference to the child Widget, as well as an 'index' property that returns a reference to the index specified when the add() method was called.
Subscribers to the "on" moment of this event, will be notified before a child is added.
Subscribers to the "after" moment of this event, will be notified after a child is added.
Event Payload:
-
e
EventFacadeThe Event Facade
removeChild
Fires when a child Widget is removed. The event object will have a 'child' property that returns a reference to the child Widget, as well as an 'index' property that returns a reference child's ordinal position.
Subscribers to the "on" moment of this event, will be notified before a child is removed.
Subscribers to the "after" moment of this event, will be notified after a child is removed.
Event Payload:
-
e
EventFacadeThe Event Facade