Adds a Select Component to a given layout.
This component is used to create a drop-down list and is most often used in a form to collect user choices.
A simple list
[ "Option 1", "Option 2", "Option 3"]
If you want a list with groupings, you can add a colon : before each item text to display as group name. Below is an example
[" : Group 1", "Option 1", "Option 2", " : Group 2", "Item 1", "Item 2"]
Properties
These are the setter and getter properties for the addSelect Component.
Example - Basic
class Main extends App
{
onStart()
{
this.main = ui.addLayout("main", "Linear", "VCenter,FillXY")
var items = ["Item 1", "Item 2", "Item 3"]
this.sel = ui.addSelect(this.main, items, "", 0.6)
this.sel.label = "Select an item"
this.sel.setOnChange( this.onChange )
}
onChange(text, index)
{
ui.showPopup("You choose " + text)
}
}
from hybrid import ui
from native import app
def OnStart():
main = ui.addLayout("main", "Linear", "VCenter,FillXY")
items = ["Item 1", "Item 2", "Item 3"]
sel = ui.addSelect(main, items, "", 0.6)
sel.label = "Select an item"
sel.setOnChange(onChange)
def onChange(text):
ui.showPopup("You choose " + text)
app.add(Main())
Example - Group title
class Main extends App
{
onStart()
{
this.main = ui.addLayout("main", "Linear", "VCenter,FillXY")
var items = [":Choices", "Item 1", "Item 2", "Item 3"]
this.sel = ui.addSelect(this.main, items, "", 0.6)
this.sel.label = "Select an item"
this.sel.setOnChange( this.onChange )
}
onChange(text, index)
{
ui.showPopup("You choose " + text)
}
}
from hybrid import ui
from native import app
def OnStart():
main = ui.addLayout("main", "Linear", "VCenter,FillXY")
items = [":Choices", "Item 1", "Item 2", "Item 3"]
sel = ui.addSelect(main, items, "", 0.6)
sel.label = "Select an item"
sel.setOnChange(onChange)
def onChange(text):
ui.showPopup("You choose " + text)
app.add(Main())
Example - Multiple selection
class Main extends App
{
onStart()
{
this.main = ui.addLayout("main", "Linear", "VCenter,FillXY")
var items = ["Item 1", "Item 2", "Item 3"]
this.sel = ui.addSelect(this.main, items, "Multiple", 0.6)
this.sel.label = "Select an item"
this.sel.setOnChange( this.onChange )
}
onChange(items, index)
{
ui.showPopup( "You choose " + items.join(", ") )
}
}
from hybrid import ui
from native import app
def OnStart():
global items
main = ui.addLayout("main", "Linear", "VCenter,FillXY")
items = ["Item 1", "Item 2", "Item 3"]
sel = ui.addSelect(main, items, "Multiple", 0.6)
sel.label = "Select an item"
sel.setOnChange(onChange)
def onChange(items):
ui.showPopup("You choose " + ", ".join(items))
app.add(Main())
Example - Outlined and small
class Main extends App
{
onStart()
{
this.main = ui.addLayout("main", "Linear", "VCenter,FillXY")
var items = ["Item 1", "Item 2", "Item 3"]
this.sel = ui.addSelect(this.main, items, "Outlined,Small,Secondary", 0.6)
this.sel.label = "Select an item"
this.sel.setOnChange( this.onChange )
}
onChange(item, index)
{
ui.showPopup( "You choose " + item )
}
}
from hybrid import ui
from native import app
def OnStart():
main = ui.addLayout("main", "Linear", "VCenter,FillXY")
items = ["Item 1", "Item 2", "Item 3"]
sel = ui.addSelect(main, items, "Outlined,Small,Secondary", 0.6)
sel.label = "Select an item"
sel.setOnChange(onChange)
def onChange(item):
ui.showPopup("You choose " + item)
app.add(Main())
Example - Radiogroup items
class Main extends App
{
onStart()
{
this.main = ui.addLayout("main", "Linear", "VCenter,FillXY")
var items = ["Item 1", "Item 2", "Item 3"]
this.sel = ui.addSelect(this.main, items, "Filled,Radio", 0.6)
this.sel.label = "Select an item"
this.sel.setOnChange( this.onChange )
}
onChange(item, index)
{
ui.showPopup( "You choose " + item )
}
}
from hybrid import ui
from native import app
def OnStart():
main = ui.addLayout("main", "Linear", "VCenter,FillXY")
items = ["Item 1", "Item 2", "Item 3"]
sel = ui.addSelect(main, items, "Filled,Radio", 0.6)
sel.label = "Select an item"
sel.setOnChange(onChange)
def onChange(item):
ui.showPopup("You choose " + item)
app.add(Main())
Example - Grouped list items
class Main extends App
{
onStart()
{
this.main = ui.addLayout("main", "Linear", "VCenter,FillXY")
var items = [":Group 1", "Item 1", "Item 2", ":Group 2", "Another item 1", "Another item 2"]
this.sel = ui.addSelect(this.main, items, "Filled", 0.6)
this.sel.label = "Select an item"
this.sel.setOnChange( this.onChange )
}
onChange(item, index)
{
ui.showPopup( "You choose " + item )
}
}
from hybrid import ui
from native import app
def OnStart():
main = ui.addLayout("main", "Linear", "VCenter,FillXY")
items = [":Group 1", "Item 1", "Item 2", ":Group 2", "Another item 1", "Another item 2"]
sel = ui.addSelect(main, items, "Filled", 0.6)
sel.label = "Select an item"
sel.setOnChange(onChange)
def onChange(item):
ui.showPopup("You choose " + item)
app.add(Main())
Example - Multiple radiogroup with titles
class Main extends App
{
onStart()
{
this.main = ui.addLayout("main", "Linear", "VCenter,FillXY")
var items = [":Group 1", "Item 1", "Item 2", ":Group 2", "Another item 1", "Another item 2"]
this.sel = ui.addSelect(this.main, items, "Outlined,Radio,Multiple", 0.6)
this.sel.label = "Select an item"
this.sel.setOnChange( this.onChange )
}
onChange(items, index)
{
ui.showPopup( "You choose " + items.join(", ") )
}
}
from hybrid import ui
def OnStart():
global items
main = ui.addLayout("main", "Linear", "VCenter,FillXY")
items = [":Group 1", "Item 1", "Item 2", ":Group 2", "Another item 1", "Another item 2"]
sel = ui.addSelect(main, items, "Outlined,Radio,Multiple", 0.6)
sel.label = "Select an item"
sel.setOnChange(onChange)
def onChange(items):
ui.show
Methods
The following methods are available on the Select object:
Boolean: Values can be `true` or `false`.
Boolean: Value can be `true` or `false`
Boolean: Sets or returns the disabled state of the control.
Boolean: Sets or returns a boolean value whether the component is enabled or disabled.
Boolean: Returns whether the control is visible or not.
Number: Fraction of the screen width. [0-1]
Number: Fraction of the screen height. [0-1]
Number: The index in which to add the item.
Number: The time in milliseconds.
Number: The z-index. A negative value behaves like `sendBackward` method.
Number: The index of the corresponding item in the select menu.
Number: The index of the item.
Number: The index of the corresponding item to remove.
Number: The z-index. A positve value behaves like `bringForward` method.
Number: Border-left thickness in pixels.
Number: Top-Left border radius in pixels.
Number: Top-Right border radius in pixels.
Number: Bottom-Left border radius in pixels.
Number: Bottom-Right border radius in pixels.
Number: `true` or `false`. You can also pass a `Boolean` to enable or disable the Select component.
Number: Fraction of the parent width.
Number: Fraction of the parent height.
Number: Fraction of the component width.
Number: Fraction of the component height. [0-1]
Number: Fraction of the component width. [0-1]
Number: Fraction of the parent width. [0-1]
Number: The x-scale of the component.Values less than `0` is smaller than the normal. While values greater than `1` is greater than the normal.
Number: The y-scale of the component. Values less than `1` is smaller than the normal. While vaues greater than `1` is greater than the normal.
Number: Fraction of the parent height. [0-1]
Number: Returns the absolute height of the control in pixels.
Number: Returns the absolute distance of the control from the left in pixels.
Number: Returns the absolute distance of the control from the top in pixels.
Number: Returns the absolute width of the control in pixels.
Number: Sets or returns the border thickness in pixels.
Number: Sets or returns the corner radius in pixels.
Number: Sets or returns the height of the control as a fraction of the parent control.
Number: Sets or returns the size of the label.
Number: Returns the distance of the control from the left.
Number: Sets or returns the maximum height of the popup container.
Number: Sets or returns the opacity of the control.
Number: Sets or returns the angle of rotation in degrees.
Number: Sets or returns the size of the text within the control.
Number: Returns the distance of the control from the top.
Number: Sets or returns the width of the control as a fraction of the parent control.
String: comma “,” separated: “Sizes: `Small` `Medium`
`Variant`: `Filled` `Outlined` `Standard`
`Margin`: `Dense` `Normal`
`Utils`: `Required` `Multiple` `Radio` `Disabled` `AutoFocus` `FullWidth`”
String: “A new item to be added.”
String: “The type of animation. Here are the available values
`bounce` `flash` `pulse` `rubberBand` `shakeX` `shakeY` `headShake` `swing` `tada` `wobble` `jello` `heartBeat`
`Back Entrances `backInDown` `backInLeft` `backInRight` `backInUp`
`Back Exits `backOutDown` `backOutLeft` `backOutRight` `backOutUp`
`Bouncing Entrances `bounceIn` `bounceInDown` `bounceInLeft` `bounceInRight` `bounceInUp`
`Bouncing exits `bounceOut` `bounceOutDown` `bounceOutLeft` `bounceOutRight` `bounceOutUp`
`Fading entrances `fadeIn` `fadeInDown` `fadeInDownBig` `fadeInLeft` `fadeInLeftBig` `fadeInRight` `fadeInRightBig` `fadeInUp` `fadeInUpBig` `fadeInTopLeft` `fadeInTopRight` `fadeInBottomLeft` `fadeInBottomRight`
`Fading exits `fadeOut` `fadeOutDown` `fadeOutDownBig` `fadeOutLeft` `fadeOutLeftBig` `fadeOutRight` `fadeOutRightBig` `fadeOutUp` `fadeOutUpBig` `fadeOutTopLeft` `fadeOutTopRight` `fadeOutBottomRight` `fadeOutBottomLeft`
`Flippers `flip` `flipInX` `flipInY` `flipOutX` `flipOutY`
`Lightspeed `lightSpeedInRight` `lightSpeedInLeft` `lightSpeedOutRight` `lightSpeedOutLeft`
`Rotating Entrances `rotateIn` `rotateInDownLeft` `rotateInDownRight` `rotateInUpLeft` `rotateInUpRight`
`Rotating Exits `rotateOut` `rotateOutDownLeft` `rotateOutDownRight` `rotateOutUpLeft` `rotateOutUpRight`
`Specials `hinge` `jackInTheBox` `rollIn` `rollOut`
`Zooming Entrances `zoomIn` `zoomInDown` `zoomInLeft` `zoomInRight` `zoomInUp`
`Zooming Exits `zoomOut` `zoomOutDown` `zoomOutLeft` `zoomOutRight` `zoomOutUp`
`Sliding Entrances `slideInDown` `slideInLeft` `slideInRight` `slideInUp`
`Sliding Exits `slideOutDown` `slideOutLeft` `slideOutRight` `slideOutUp`.”
String: “The name of the menu item.”
String: “The mode of the measurements. Values can be `px` or `%`”
String: “The name of the item to remove.”
String: “Border color in hexadecimal form `#rrggbb`”
String: “Border-styles. Values can be `dotted` `dashed` `solid` `double` `groove` `ridge` `inset` and `outset`. Default is `solid`”
String: “Unit. Values are `px` `rem` or `%`.”
String: “`px` or `%`”
String: “The size thickness mode. Can be `px`”
String: “Unit of measurement. Can be `px` or `%` or any css unit of measurement.”
String: A hexadecimal color of the form #rrggbb
String: The path to your image file.
String: Sets or returns the border color. Color is in hexadecimal form #rrggbb
String: Sets or returns the border style. Values can be dotted, dashed, solid, double, groove, ridge, inset and outset. Default is solid.
String: Sets or returns the relative path to the font-family use.
String: Sets or returns the color of the icon in hexadecimal format #rrggbb
String: Sets or returns the label text.
String: Sets or returns the color of the label text in hexadecimal format #rrggbb
String: Sets or returns the options of the control.
String: Sets or returns the color of the popup in hexadecimal format.
String: Sets or returns the size variant of the Select Component. Values can be Small or Medium
String: Sets or returns the color of the text.
String: Returns the type of the control.
String: Sets or returns the value of the Select Component. For Select with Multiple options, the value is an array of string items. You can also pass the index of the selected item. Pass an array of indexes for multiple selection.
String: Sets or returns the variant of the Select Component. Values can be Standard Filled and Outlined
String: Sets or returns the visibility of the control.
Object: The parent layout where to add the control
Object: A comma separated string or array of options
Object: The pointer event object.
Object: The click event object.
Object: Returns the parent layout control.
Object: Returns the position of the control. The returned object has left top right and bottom props.
List: The list of items for the Select options
List: Sets or returns the list items. You can also pass a comma separated string of items.
List: Sets or returns the margin of the control. Works on controls with Linear parent only. You can also pass a number to set equal margins for all sides.
List: Sets or returns the padding of the control. You can also pass a number to set equal padding for all sides.
function()
sel.addItem
Adds an item on the select component options list
sel.animate
Animate the component
sel.bringForward
Bring this component forward by a given z-index
sel.destroy
Destroy the component
sel.getEnabled
Get the enabled state of an item in the select menu
sel.getEnabledByName
Get the enabled state of an item in the menu popup
sel.getItem
Returns the item at a given index
sel.getPosition
Returns the position of the component. The return object is of the form `{ left, top, right, bottom
sel.gone
Destroy the component
sel.hide
Hide the component
sel.popItem
Removes an item at the end of the list items
sel.removeItemByIndex
Removes an item in the select component item list by its index
sel.removeItemByName
Removes an item in the select component item list by its name
sel.sendBackward
Bring this component backward by a given z-index
sel.setBorder
Sets the border line for the component container
sel.setCornerRadius
Sets the corner radius of the component
sel.setEnabled
Enable or disable the select component
sel.setEnabledByName
Enable or disable an item in the menu popup
sel.setList
Sets the list items in the menu popup
sel.setMargins
Sets the margin of the component
sel.setOnChange
Sets a callback function when the value changes
sel.setOnClose
Sets a callback function when the menu dialog is close
sel.setOnContextMenu
Adds a callback function on right click
sel.setOnOpen
Sets a callback function when the menu is open
sel.setOnTouch
Adds a callback handler when the component is touch
sel.setPadding
Sets the padding component container
sel.setPosition
Sets the position of the component relative to its parent dimensions
sel.setScale
Sets the x and y scaling of the component
sel.setSize
Sets the size of the component
sel.shifItem
Removes an item at the beginning of the list items
sel.show
Show the component