LogStatus-btnTypeOne
Older form of the status bar button structure (input controls without settings), still supported. New code should use LogStatus-btnTypeTwo; the field reference is under "Status bar buttons" in LogStatus.
A button can be output to the status bar on its own or embedded in a status bar table. The controls in the popup shown after a click are configured with input (one control) or group (a group of controls), and what is submitted is received by GetCommand. For example, a button that pops up a number input:
json
{
"type": "button",
"cmd": "open",
"name": "Open Position",
"input": {
"name": "Position Size",
"type": "number",
"defValue": 1
}
}
Attributes
| Name | Type | Description |
type | string | For button controls, fixed as: |
class | string | Button style, a Bootstrap button class name such as |
name | string | The text displayed on the button control, i.e., the button name. |
cmd | string | The interactive command content sent to the strategy when the button control triggers a click operation. |
description | string | Description information for the button control. This description is displayed when the mouse hovers over the button in the status bar. |
disabled | bool | Set the button as disabled (true) or enabled (false). |
input | object | The input control in the popup shown after the button is clicked; see the " |
group | array | A group of controls in the popup shown after the button is clicked; each element has the same structure as |
See Also
Remarks
Fields of input (each element of group is the same):
| Field | Description |
|---|---|
name | Title of the control in the popup. |
description | Description of the control in the popup. |
type | Control type: number number input, string string input, selected drop-down, boolean switch. |
defValue | Default value of the control. A drop-down can list its options here, separated by vertical bars; when options is set it is the default option, an array for multiple selection. |
options | Options of a drop-down: strings or {text: "label", value: "value"} objects. |
multiple | When true, the drop-down allows multiple selection. |
Example of class attribute values for button JSON structure in status bar:
javascript
function main() {
var table = {
type: "table",
title: "Status Bar Button Styles",
cols: ["Default", "Primary", "Success", "Info", "Warning", "Danger"],
rows: [
[
{"type":"button", "class": "btn btn-xs btn-default", "name": "Default"},
{"type":"button", "class": "btn btn-xs btn-primary", "name": "Primary"},
{"type":"button", "class": "btn btn-xs btn-success", "name": "Success"},
{"type":"button", "class": "btn btn-xs btn-info", "name": "Info"},
{"type":"button", "class": "btn btn-xs btn-warning", "name": "Warning"},
{"type":"button", "class": "btn btn-xs btn-danger", "name": "Danger"}
]
]
}
LogStatus("`" + JSON.stringify(table) + "`")
}
group field and input field usage example:
javascript
function main() {
// Status bar button control (implemented with input field) - The dropdown control on the page triggered by testBtn1 button uses options field to set options and defValue field to set default option. This differs from other examples in this chapter that directly use defValue to set options.
var testBtn1 = {
type: "button",
name: "testBtn1",
cmd: "cmdTestBtn1",
input: {name: "testBtn1ComboBox", type: "selected", options: ["A", "B"], defValue: 1}
}
/*
Status bar button control (implemented with input field) - The dropdown control on the page triggered by testBtn2 button uses options field to set options. The options field supports not only strings,
but also ```{text: "description", value: "value"}``` structure. Use defValue field to set default option, which can be multiple selections (implemented through array structure). Multiple selection requires setting additional field multiple to true.
*/
var testBtn2 = {
type: "button",
name: "testBtn2",
cmd: "cmdTestBtn2",
input: {
name: "testBtn2MultiComboBox",
type: "selected",
description: "Implement dropdown multi-select",
options: [{text: "Option A", value: "A"}, {text: "Option B", value: "B"}, {text: "Option C", value: "C"}],
defValue: ["A", "C"],
multiple: true
}
}
// Status bar grouped button control (implemented with group field) - The dropdown control on the page triggered by testBtn3 button uses options field to set options, and also supports directly using defValue to set options.
var testBtn3 = {
type: "button",
name: "testBtn3",
cmd: "cmdTestBtn3",
group: [
{name: "comboBox1", label: "labelComboBox1", description: "Dropdown 1", type: "selected", defValue: 1, options: ["A", "B"]},
{name: "comboBox2", label: "labelComboBox2", description: "Dropdown 2", type: "selected", defValue: "A|B"},
{name: "comboBox3", label: "labelComboBox3", description: "Dropdown 3", type: "selected", defValue: [0, 2], multiple: true, options: ["A", "B", "C"]},
{
name: "comboBox4",
label: "labelComboBox4",
description: "Dropdown 4",
type: "selected",
defValue: ["A", "C"],
multiple: true,
options: [{text: "Option A", value: "A"}, {text: "Option B", value: "B"}, {text: "Option C", value: "C"}, {text: "Option D", value: "D"}]
}
]
}
while (true) {
LogStatus("`" + JSON.stringify(testBtn1) + "`\n", "`" + JSON.stringify(testBtn2) + "`\n", "`" + JSON.stringify(testBtn3) + "`\n")
var cmd = GetCommand()
if (cmd) {
Log(cmd)
}
Sleep(5000)
}
}