Class: UWA.Controls.Picker

UWA/Controls/Picker. UWA.Controls.Picker

new UWA.Controls.Picker(options)

Abstract Picker component to build simple picker inputs.

Available Events
Event Description
onNavigationClick Triggered when the user clicks on a navigation button
onOpen Triggered when the dropdown opens
onClose Triggered when the dropdown closes
Example

Extend the Picker to provide three choices

var ThreeChoicesPicker = UWA.Controls.Picker.extend({
    options: {
        choices: ['a', 'b', 'c']
    },
    buildContent: function () {
        var picker = this;
        return this.options.choices.map(function (choice) {
            return UWA.createElement('input', {
                type: 'button',
                value: choice,
                events: {
                    click: function () {
                        picker.setValue(choice);
                        picker.dispatchEvent('onChange', [choice]);
                        picker.toggle(`false`);
                    }
                }
           });
       });
    }
});

var picker = new ThreeChoicesPicker();
picker.inject(container);
Parameters
Name Type Description
options Object

Options hash or a option/value pair.

Properties
Name Type Argument Description
navigation Object <optional>

Set the initial navigation menu. See setNavigation

button Element <optional>

If defined, use this DOM element or descriptor to display a button

button String <optional>

Type of input to print the value. For now, it can be 'text' to display the value as text, or a falsy value to hide the value.

dropdownOptions Object <optional>

Options passed to construct the <UWA.Controls.DropDown.Pointy> instance

dropdownContainer Element <optional>

Where to inject the dropdown. Defaults to this control container

Extends

Index

Members

name :String

The input name. Default: 'uwa-picker'.

Type
  • String

<protected> _hiddenInput

Properties:
Name Type Description
_hiddenInput Boolean

If the input element should be displayed or emulated with some generated DOM. Default: false.

Inherited From:

<protected> elements :Object

The current control elements.

Type
  • Object
Inherited From:

Methods

buildSkeleton()

Overrides UWA.Controls.Input.buildSkeleton.

buildContent() → {Element}

Build the dropdown content. To override.

Returns

The dropdown content.

Type
Element

buildNavigation() → {Element}

Build the navigation menu.

Returns

Element or Element descriptor. The navigation menu.

Type
Element

buildNavigationItem(item) → {Element}

Build one navigation item.

Parameters
Name Type Description
item Object

The navigation descriptor

Returns

Element or Element descriptor. The navigation item.

Type
Element

syncInput()

Overrides <UWA.Controls.Input.buildSkeleton>

isOpen() → {Boolean}

Returns

true if the dropdown is open.

Type
Boolean

focus()

Overrides <UWA.Controls.Input.focus>

open() → {this}

Open the dropdown

Returns
Type
this

close() → {this}

Close the dropdown

Returns
Type
this

toggle(f) → {this}

Toggle the dropdown

Parameters
Name Type Description
f Boolean

If defined, opens (true) or closes (false) the dropdown

Returns
Type
this

onClick()

Default onClick handler

onOpen()

Default onOpen handler

onClose()

Default onClose handler

onNavigationClick()

Default onNavigationClick handler

buildInput() → {DOMElement}

Build the native input element. To override.

Returns

The native input element

Type
DOMElement
Inherited From:

isDisabled() → {Boolean}

Get if this input is disabled

Returns
Type
Boolean
Inherited From:

setDisabled(y) → {this}

Set the input as disabled

Parameters
Name Type Argument Default Description
y Boolean <optional>
true

If false, enable the input.

Returns
Type
this
Inherited From:

getValue() → {String}

Get the input value. To override if needed.

Returns

The input value

Type
String
Inherited From:

setValue(value) → {this}

Set the input value. To override if needed.

Parameters
Name Type Description
value String

The new value

Returns
Type
this
Inherited From:

getContent() → {HTMLelement}

Returns control content.

Returns

Control container.

Type
HTMLelement
Inherited From:

getInputElement() → {HTMLelement}

Returns the native input element

Returns
Type
HTMLelement
Inherited From:

inject(element, where) → {this}

Inject control in the dom.

Parameters
Name Type Argument Description
element HTMLelement

Dom target

where String <optional>

Where to inject

Returns
Type
this
Inherited From:

remove() → {this}

Remove the control from the dom

Returns
Type
this
Inherited From:

getClassNames(suffixes) → {String}

Generate a CSS class name based on the class name property, its parent classes, and the options "className". It should be used internally (in the control).

Example
var Input = UWA.Controls.Abstract.extend({
   name: 'uwa-input',

   options: {
       className: '',
   },

   buildSkeleton: function () {
       this.elements.container = UWA.createElement('div', { 'class': this.getClassNames() });
       this.elements.content = UWA.createElement('div', { 'class': this.getClassNames('-content') });
   }
});

var Radio = Input.extend({
   name: 'uwa-inputradio'
});

new Radio({
    className: 'toto black'
});
// container will have the class 'toto black uwa-inputradio uwa-input'
// content will have the class 'toto black uwa-inputradio-content uwa-input-content'
Parameters
Name Type Description
suffixes String

All parameters should be strings, used as suffix to append to the UWA.Class names of the inheritance chain.

Returns

The generated CSS class name.

Type
String
Inherited From:

hide()

Hide control content.

Inherited From:

show()

Show control content.

Inherited From:

destroy()

Destroy the control elements and its children. Remove all events and remove the element from the dom. This control and its children should not be used after this.

Inherited From: