|
| 1 | +# comboBox |
| 2 | + |
| 3 | +The`comboBox` class provides an interface to manage properties and actions of [Combo Box](https://developer.4d.com/docs/20/FormObjects/comboBoxOverview) widgets using an `Object` as data source. |
| 4 | + |
| 5 | +The `comboBox` class is available via the [`form`](form.md#objects) class through the `ComboBox` interface. |
| 6 | + |
| 7 | +```4d |
| 8 | +This.form:=cs.form.new(This) |
| 9 | +... |
| 10 | +This.myCombo:=This.form.DropDown("Combo Box"; {\ {values: ["apples"; "nuts"; "pears"; "oranges"; "carrots"]; \ ordered: True; \ automaticExpand: True; \ automaticInsertion: True}) |
| 11 | +``` |
| 12 | + |
| 13 | +In the form editor, you set the *Variable or expression* property of the drop-down list to `formGetInstance.myCombo.data` and you can later do: |
| 14 | + |
| 15 | +```4d |
| 16 | +// Get user selection |
| 17 | +var $value : Text:This.myCombo.value |
| 18 | +``` |
| 19 | + |
| 20 | +This class is, more generally, available from the `cs` class store, or `cs.ui` class store if you use the `UI` component: |
| 21 | + |
| 22 | +```4d |
| 23 | +Form.Cities:=cs.ui.comboBox.new("Combo Box"; {\ values: ["Philadelphia"; "Pittsburg"; "Grand Blanc"; "Bad Axe"; "Frostbite Falls"; "Green Bay"]; \ ordered: True; \ automaticExpand: True; \ automaticInsertion: True}) |
| 24 | +``` |
| 25 | + |
| 26 | +In the form editor, you set the *Variable or expression* property of the drop-down list to `Form.Cities.data` and you can later retrieve the user's selection like this: |
| 27 | +```4d |
| 28 | +// Get user selection |
| 29 | +var $value : Text:=Form.Cities.value |
| 30 | +``` |
| 31 | +<br> |
| 32 | +<hr> |
| 33 | + |
| 34 | +📌 <b>Important</b> |
| 35 | + |
| 36 | +1. This class inherit from the [`dropDown`](dropDown.md) class |
| 37 | +2. To simplify the distinction between form objects and object type, this documentation uses the term `widget` for all form objects, whether static (a line, a rectangle…) or not (a button, a subform…). |
| 38 | +3. All functions that return `This` return the current *widget* object and can include one call after another. |
| 39 | + |
| 40 | + |
| 41 | +## <a name="Constructor">cs.comboBox.new()</a> |
| 42 | + |
| 43 | +**cs.comboBox.new** ( ) : `cs.comboBox` |
| 44 | +<br>**cs.comboBox.new** ( *name* : Text ) : `cs.comboBox` |
| 45 | +<br>**cs.comboBox.new** ( *name* : Text ; *data* : Object ) : `cs.comboBox` |
| 46 | +<br>**cs.comboBox.new** ( *name* : Text ; *data* : Object ; *parent* : Object ) : `cs.comboBox` |
| 47 | + |
| 48 | +|Parameter|Type||Description| |
| 49 | +|---|---|---|---| |
| 50 | +| name | Text | →| Widget name | |
| 51 | +| data | `Object` | → | Parameters to be used for the Combo Box management | |
| 52 | +| parent | **cs**.form | → | `form` object containing the *widget* | |
| 53 | +| result | **cs**.dropDown | ← | New `cs.dropDown` |
| 54 | + |
| 55 | +### Description |
| 56 | + |
| 57 | +`cs.comboBox.new()` creates & returns a new instance of the class. |
| 58 | + |
| 59 | + * The optional `data` parameter is the object to be used as the data source of the drop-down list. The object contain the following properties: |
| 60 | + |
| 61 | +|Parameter|Type| Mandatory |Description| |
| 62 | +|---|---|:---:|---| |
| 63 | +`automaticExpand` | Boolean | No | Enable list to be displayed on getting focus \*.<br>Default is **False** |
| 64 | +`automaticInsertion` | Boolean | No | Enable automatic insertion into the list in memory \*\*.<br>Default is **False** |
| 65 | +`currentValue` | same as `values` | No | Currently selected item (used as placeholder value if set by code) |
| 66 | +`index` | Integer | No | Index of the currently selected item (value from 0 to `values.length-1`). |
| 67 | +`ordered` | Boolean | No | Keep the list ordered.<br>Default is **False** |
| 68 | +`placeholder` | same as `values` | No | Default is `currentValue` |
| 69 | +`values` | Collection | Yes | Collection of scalar values. All values must be of the same type. <br>Supported types:<br> • strings<br> • numbers<br> • dates<br> • times<br>If empty or not defined, the drop-down list is empty. |
| 70 | + |
| 71 | +* The optional `parent` parameter is the [`cs.form`](form.md) object containing the *widget*. This parameter is automatically set if instantiation is performed via a [form widget instantiation function](form.md#objects) of the `cs.form` class. |
| 72 | +* If the `name` parameter is ommited, the constructor use the result of **[OBJECT Get name](https://doc.4d.com/4Dv19/4D/19/OBJECT-Get-name.301-5392401.en.html)** (_Object current_ ) |
| 73 | + |
| 74 | +> ⚠️ Omitting the widget name can only be used if the constructor is called from the object method. |
| 75 | +
|
| 76 | +📌 The constructor checks that all values are of the same type. If this is not the case, an error is raised. |
| 77 | + |
| 78 | +# Summary |
| 79 | + |
| 80 | +## <a name="Inherited">Inherited Properties & Functions</a> |
| 81 | + |
| 82 | +Inherited properties and functions are described in the parent classes: |
| 83 | + |
| 84 | +* [`static` class](static.md) |
| 85 | +* [`widget` class](widget.md) |
| 86 | +* [`dropDown` class](dropDown.md) |
| 87 | + |
| 88 | +## <a name="Properties">Properties</a> |
| 89 | + |
| 90 | +|Properties|Description|Type|default|Writable| |
| 91 | +|:----------|:-----------|:-----------|:-----------|:-----------:| |
| 92 | +|**.automaticExpand** | Enable list to be displayed on getting focus\* | `Boolean` | **False** | <font color="green">✓</font> |
| 93 | +|**.automaticInsertion** | Enable automatic insertion into the list in memory\*\* | `Boolean` | **False** | <font color="green">✓</font> |
| 94 | +|**.filter** | Modify the entry filter | `Integer`\*\*\* \| `Text` | Depending on the type of values | <font color="green">✓</font> |
| 95 | +|**.ordered** | Does the values list always need to be sorted? | `Boolean` | **False** | <font color="green">✓</font> |
| 96 | + |
| 97 | +<br>\*\*\* Use [4D constants](https://developer.4d.com/docs/commands/value-type) (possible values: _Is longint_, _Is real_, _Is time_ or _Is date_. Default is _Is text_) for default predefined formats or pass the filter definition as text. |
| 98 | + |
| 99 | +## <a name="Functions">Functions</a> |
| 100 | + |
| 101 | +| Functions | | |
| 102 | +|:-------- |:------ | |
| 103 | +|[.**expand**](#expand) ( { *expand* }) → `This`| Display the values list - to use in the On getting focus event |
| 104 | +|[.**insert**](#insert) ( { *item* }{; *order* }) → `This` | Insert an item (or the current value).<br>Sortes the list, if *order* is **True**, even if `ordered` property is **False**. <br>If *order* is omitted, the property `ordered` is used. |
| 105 | +|.**listModified** ( ) → `Boolean` | Returns **True** if the values list was modified by a call to the function `insert()`. |
| 106 | + |
| 107 | +<hr> |
| 108 | +\* If **True**, the _On getting focus_ event is automatically activated for the widget, and you must call the [`.expand()`](#expand) function when this event is triggered. |
| 109 | +<br>\*\* If **True** you must call the [`.insert()`](#insert) function (without parameter) when the event _On data change_ is triggered. |
| 110 | + |
| 111 | +# <a name="expand">.expand()</a> |
| 112 | + |
| 113 | +.**expand** ( ) → `This` |
| 114 | +<br>.**expand** ( *force* ) → `This` |
| 115 | + |
| 116 | +|Parameter|Type||Description| |
| 117 | +|---|---|---|---| |
| 118 | +| force | Boolean | → | Force expansion | |
| 119 | +| result | `This`| ← | Current widget object | |
| 120 | + |
| 121 | +### Description |
| 122 | + |
| 123 | +This function expands the list of values. |
| 124 | + |
| 125 | +* If *force* is omitted, the `automaticExpand` property is used to allow or disallow expansion. |
| 126 | +* Must be call during the wiget's _On getting focus_ event like this, if the `automaticExpand` property is **True**: |
| 127 | + |
| 128 | +```4D |
| 129 | +If (FORM Event.code=On Getting Focus) myCombo.expand() End if |
| 130 | +``` |
| 131 | +# <a name="insert">.insert()</a> |
| 132 | + |
| 133 | +.**insert** ( ) → `This` |
| 134 | +<br>.**insert** ( *item* ) → `This` |
| 135 | +<br>.**insert** ( *order* ) → `This` |
| 136 | +<br>.**insert** ( *item* ; *order*) → `This` |
| 137 | + |
| 138 | +|Parameter|Type||Description| |
| 139 | +|---|---|---|---| |
| 140 | +| item | same as `values` | → | Item to be added to the list of values in memory| |
| 141 | +| order | same as `values` | → | Item to be added to the list of values in memory| |
| 142 | +| result | `This`| ← | Current widget object | |
| 143 | + |
| 144 | +### Description |
| 145 | + |
| 146 | +This function add an item to the list of values in memory & keep the list ordered if any. |
| 147 | + |
| 148 | +* If *item* is omitted, the current `value` is used. |
| 149 | +* If *order* is omitted, the `ordered` property is used. |
| 150 | +* Could be call during the wiget's _On Data Change_ event like this: |
| 151 | + |
| 152 | +```4D |
| 153 | +If (FORM Event.code=On Data Change) myCombo.insert() End if |
| 154 | +``` |
| 155 | +* The widget's function can be called anywhere in the code to add one or more elements to the list of values: |
| 156 | + |
| 157 | +```4D |
| 158 | +myCombo.insert("New Item") |
| 159 | +``` |
| 160 | + |
| 161 | +* In any case, when the widget is unloaded, the list of values is lost. If you wish, you can retrieve the collection of values in the `values` property and save it. |
| 162 | + |
| 163 | + |
| 164 | + |
| 165 | + |
|
0 commit comments