TK.Select

new Select(optionsopt)

TK.Select provides a TK.Button with a select list to choose from a list of {@TK.SelectEntry}.

Parameters:
Name Type Attributes Default Description
options Object <optional>
{ }

An object containing initial options.

Properties:
Name Type Attributes Default Description
options.selected Integer | Boolean <optional>
false

The index of the selected {@TK.SelectEntry}. Set to false to unselect any already selected entries.

options.value mixed <optional>

The value of the selected entry.

options.auto_size Boolean <optional>
true

If true, the TK.Select is auto-sized to be as wide as the widest {@TK.SelectEntry}.

options.entries Array.<Object> <optional>
[]

The list of {@TK.SelectEntry}. Each member is an object with the two properties title and value, a string used as label for constructing a {@TK.SelectEntry} or an instance of {@TK.SelectEntry}.

Source:

Extends

Members

_list :HTMLListElement

A HTML list for displaying the entry titles. Has class toolkit-select-list.

Source:

element :HTMLDivElement

The main DIV container. Has class toolkit-select.

Overrides:
Source:

entries :Array

An array containing all entry objects with members title and value.

Source:

Members inherited from TK.Button

icon :TK.Icon

The TK.Icon widget.

label :TK.Label

The TK.Label of the button.

Methods

add_entries(entries)

Adds new TK.SelectEntry to the end of the list to select from.

Parameters:
Name Type Description
entries Array

An array of TK.SelectEntry to add to the end of the list of TK.SelectEntry to select from. Please refer to TK.Select#add_entry for more details.

Source:

add_entry(entry)

Adds a single TK.SelectEntry to the end of the list.

Parameters:
Name Type Description
entry mixed

A string to be displayed and used as the value, an object with members title and value or an instance of TK.SelectEntry.

Source:
Fires:
  • TK.Select.event:entryadded

clear()

Remove all TK.SelectEntry from the list.

Source:
Fires:
  • TK.Select#event:cleared

current() → {TK.SelectEntry|Boolean}

Get the currently selected TK.SelectEntry.

Source:
Returns:

The currently selected TK.SelectEntry or false.

Type
TK.SelectEntry | Boolean

current_index() → {Integer|Boolean}

Get the currently selected TK.SelectEntry's index. Just for the sake of completeness, this function abstracts options.selected.

Source:
Returns:

The index of the currently selected TK.SelectEntry or false.

Type
Integer | Boolean

current_value() → {Mixed|Boolean}

Get the currently selected TK.SelectEntry's value.

Source:
Returns:

The value of the currently selected TK.SelectEntry or false.

Type
Mixed | Boolean

entry_by_index(index) → {TK.SelectEntry|Boolean}

Get a TK.SelectEntry by its index.

Parameters:
Name Type Description
index Integer

The index of the TK.SelectEntry.

Source:
Returns:

The TK.SelectEntry or false.

Type
TK.SelectEntry | Boolean

entry_by_title(title) → {TK.SelectEntry|Boolean}

Get a TK.SelectEntry by its title/label.

Parameters:
Name Type Description
title String

The title of the TK.SelectEntry.

Source:
Returns:

The TK.SelectEntry or false.

Type
TK.SelectEntry | Boolean

entry_by_value(value) → {TK.SelectEntry|False}

Get a TK.SelectEntry by its value.

Parameters:
Name Type Description
value Mixed

The value of the TK.SelectEntry.

Source:
Returns:

The TK.SelectEntry or false.

Type
TK.SelectEntry | False

index_by_entry(entry) → {Integer|Boolean}

Get the index of a TK.SelectEntry by the TK.SelectEntry itself.

Parameters:
Name Type Description
entry TK.SelectEntry

The TK.SelectEntry.

Source:
Returns:

The index of the entry or false.

Type
Integer | Boolean

index_by_title(title) → {Integer|Boolean}

Get the index of a TK.SelectEntry by its title/label.

Parameters:
Name Type Description
title String

The title/label of the TK.SelectEntry.

Source:
Returns:

The index of the entry or false.

Type
Integer | Boolean

index_by_value(value) → {Integer|Boolean}

Get the index of a TK.SelectEntry by its value.

Parameters:
Name Type Description
value Mixed

The value of the TK.SelectEntry.

Source:
Returns:

The index of the entry or false.

Type
Integer | Boolean

remove_entry(entry)

Remove an entry from the list.

Parameters:
Name Type Description
entry TK.SelectEntry

The TK.SelectEntry to be removed from the list.

Source:
Fires:
  • TK.Select#event:entryremoved

remove_id(index)

Remove a TK.SelectEntry from the list by its index.

Parameters:
Name Type Description
index Integer

The index of the TK.SelectEntry to be removed from the list.

Source:
Fires:
  • TK.Select#event:entryremoved

remove_title(title)

Remove an entry from the list by its title.

Parameters:
Name Type Description
title string

The title of the entry to be removed from the list.

Source:
Fires:
  • TK.Select#event:entryremoved

remove_value(value)

Remove a TK.SelectEntry from the list by its value.

Parameters:
Name Type Description
value mixed

The value of the TK.SelectEntry to be removed from the list.

Source:
Fires:
  • TK.Select#event:entryremoved

select(index)

Select a TK.SelectEntry by its index.

Parameters:
Name Type Description
index Integer

The index of the TK.SelectEntry to select.

Source:

select_title(title)

Select a TK.SelectEntry by its title.

Parameters:
Name Type Description
title mixed

The title of the TK.SelectEntry to select.

Source:

select_value(value)

Select a TK.SelectEntry by its value.

Parameters:
Name Type Description
value mixed

The value of the TK.SelectEntry to select.

Source:

set_entries(entries)

Replaces the list of TK.SelectEntry to select from with an entirely new one.

Parameters:
Name Type Description
entries Array

An array of TK.SelectEntry to set as the new list to select from. Please refer to TK.Select#add_entry for more details.

Source:

show_list(show)

Show or hide the select list

Parameters:
Name Type Description
show boolean

true to show and false to hide the list of TK.SelectEntry.

Source:

value_by_entry(entry) → {mixed}

Get the value of a TK.SelectEntry.

Parameters:
Name Type Description
entry TK.SelectEntry

The TK.SelectEntry.

Source:
Returns:

The value of the TK.SelectEntry.

Type
mixed

value_by_index(index) → {Mixed|Boolean}

Get a value by its TK.SelectEntry index.

Parameters:
Name Type Description
index Integer

The index of the TK.SelectEntry.

Source:
Returns:

The value of the TK.SelectEntry or false.

Type
Mixed | Boolean

value_by_title(title) → {Mixed|Boolean}

Get the value of a TK.SelectEntry by its title/label.

Parameters:
Name Type Description
title String

The title of the TK.SelectEntry.

Source:
Returns:

The value of the TK.SelectEntry or false.

Type
Mixed | Boolean

Methods inherited from TK.Widget

add_child(child)

Registers a widget as a child widget. This method is used to build up the widget tree. It does not modify the DOM tree.

add_children(a)

Registers an array of widgets as children.

all_children()

Returns an array of all children.

enable_draw()

Schedules this widget for drawing.

force_hide()

This is an alias for hide, which may be overloaded. See TK.Container for an example.

force_show()

This is an alias for hide, which may be overloaded. See TK.Container for an example.

get_style()

Returns the computed style of this widgets DOM element.

hidden()

Returns the current hidden status.

hide()

Make the widget hidden. This does not modify the DOM, instead it will stop rendering this widget. Options changed after calling hide will only be rendered (i.e. applied to the DOM) when the widget is made visible again using TK.Widget#show.

remove_child(child)

Removes a child widget. Note that this method only modifies the widget tree and does not change the DOM.

remove_children(a)

Removes an array of children.

set(key, value)

Sets an option.

set_style()

Sets a CSS style property in this widgets DOM element.

show()

Make the widget visible. This does not modify the DOM, instead it will only schedule the widget for rendering.

toggle_hidden()

TK.Toggle the hidden status. This is equivalent to calling hide() or show(), depending on the current hidden status of this widget.

visible_children()

Returns an array of all visible children.

widgetize()

Set the DOM elements of this widgets. This method is usually only used internally. Basically it means to add the id from options and set a basic CSS class. If delegate is true, basic events will be delegated from the element to the widget instance if classify is true, CSS functions will be bound to the widget instance.

Methods inherited from TK.Base

add_event(event, func, prevent, stop)

Register an event handler.

add_events(events, func)

Add multiple event handlers at once, either as dedicated event handlers or a list of event descriptors with a single handler function.

delegate_events(element) → {HTMLElement}

Delegates all occuring DOM events of a specific DOM node to the widget. This way the widget fires e.g. a click event if someone clicks on the given DOM node.

destroy()

Destroys all event handlers and the options object.

fire_event(event, …args)

Fires an event.

fire_events(events)

Fires several events.

get(key)

Get the value of an option.

has_event_listeners(event) → {boolean}

Test if the event descriptor has some handler functions in the queue.

remove_event(event, fun)

Removes the given function from the event queue. If it is a native DOM event, it removes the DOM event listener as well.

remove_events(events, func)

Remove multiple event handlers at once, either as dedicated event handlers or a list of event descriptors with a single handler function.

set_options(optionsopt)

Merges a new options object into the existing one, including deep copies of objects. If an option key begins with the string "on" it is considered as event handler. In this case the value should be the handler function for the event with the corresponding name without the first "on" characters.

userset(key, value)

Sets an option by user interaction. Emits the userset event. The userset event can be cancelled (if an event handler returns false), in which case the option is not set. Returns true if the option was set, false otherwise. If the option was set, it will emit a useraction event.

Events

cleared

Is fired when the list is cleared.

Source:

entryremoved

Is fired when a new entry is added to the list.

Parameters:
Name Type Description
entry Object

An object containing the members title and value.

Source:

entryadded

Is fired when a new TK.SelectEntry is added to the list.

Parameters:
Name Type Description
entry TK.SelectEntry

A new TK.SelectEntry.

Source:

select

Is fired when a selection was made by the user. The arguments are the value of the currently selected TK.SelectEntry, its index, its title and the TK.SelectEntry instance.

Parameters:
Name Type Description
value mixed

The value of the selected entry.

value number

The ID of the selected entry.

value string

The title of the selected entry.

value string

The title of the selected entry.

Source:

useraction

The useraction event is emitted when a widget gets modified by user interaction. The event is emitted for the options selected and value.

Parameters:
Name Type Description
name string

The name of the option which was changed due to the users action

value mixed

The new value of the option

Source:

Events inherited from TK.Widget

GenericDOMEvents

Generic DOM events. Please refer to W3Schools for further details.

classified

Is fired when a widget is classified.

destroy

Is fired when a widget is destroyed.

doubleclick

Is fired after a double click appeared. Set dblclick to 0 to disable click event handling.

hide

The hide event is emitted when a widget is hidden and is not rendered anymore. This happens both with browser visibility changes and also internally when using layout widgets such as TK.Pager.

initialized

Is fired when a widget is initialized.

redraw

Is fired when a redraw is executed.

resize

The resize event is emitted whenever a widget is being resized. This event can be used to e.g. measure its new size. Note that some widgets do internal adjustments after the resize event. If that is relevant, the TK.Widget#resized event can be used, instead.

resized

The resized event is emitted after each rendering frame, which was triggered by a resize event.

set

The set event is emitted when an option was set using the TK.Widget#set method. The arguments are the option name and its new value.

Note that this happens both for user interaction and programmatical option changes.

show

The show event is emitted when a widget is shown and is being rendered. This is the counterpart to TK.Widget#hide.

stylized

Is fired when a widget is stylized.

visibility

Is fired when the visibility state changes. The first argument is the visibility state, which is either true or false.

widgetize

Is fired when a widget is widgetized.

Events inherited from TK.Base

delegated

Is fired when an element is delegated.

set_[option]

Is fired when an option is set.