« Back to Product

Documentation

Button

A button that executes an action when pressed.

Example

Parameters

Parameter Description
caption Visible caption of the button
confirm (optional) (default: "") If this parameter does not contain an empty string, the text is displayed in a yes/no dialog when the button is pressed. The onClick action is only carried out if the dialog is confirmed with "Yes". If the parameter is empty, the action is carried out directly. (since IP-Symcon 5.0)
download (optional) (default: "") If this parameter is not an empty string and the output of the onClick script is a Data-URL, the output is downloaded as a text file with the name of the download parameter. (since IP-Symcon 7.0)
enabled (optional) (default: true) If true, the button can be used, otherwise it is displayed as deactivated (since IP-Symcon 5.2)
label Name and visible caption of the button (deprecated, cannot be changed)
link (optional) If this parameter is true, the output of the onClick script is opened as a link. If it is false, the output is displayed as a dialog in the configuration form. If the parameter is not set, a decision whether it is opened as a link or displayed in the dialog is made on the basis of the output (see info box). (since IP-Symcon 5.1)
name (optional) Name of the button
onClick Script that is executed when the button is clicked. If the script consists of several lines, the individual lines can also be defined as an array (arrays are supported since version 6.0). No PHP-tags are required. There are a few other variables available, which are discussed in the information field below.
type Button
visible (optional) (default: true) If true, the button is visible, otherwise it is invisible (since IP-Symcon 5.2)
width (optional) Fixed width of the button in pixels or % as a string, e.g. "40%" or "250px". If the value is not set or "", the width is automatically selected based on the caption (since IP-Symcon 5.2)
Warning

The $id variable is available in all areas. In addition, variables are created for all form fields, provided a name has been assigned. The variable can then be used as a $Name.

Warning

If the parameter onClick contains an "echo" in combination with 'http'/'https', the browser is opened and the URL is called. If there is an "echo" in combination with a 'mailto:', the default mail program is opened with all the parameters set (available since IP-Symcon 4.1)

Example

//The example returns the instance ID.
    { "type": "Button", "caption": "On", "onClick": "echo $id;" }

    // Special example:
    // The example opens the browser with the specified address when "clicked": 'https://www.symcon.de'
    {
        "type": "Button",
        "caption": "Symcon",
        "onClick": "echo 'https://www.symcon.de';"
    }

    // The example asks whether the value of a variable should actually be set to 0
    {
        "type": "Button",
        "caption": "Reset",
        "onClick": "SetValue(12345, 0);",
        "confirm": "This sets the variable back to 0. Important data can be lost in the process. Are you sure?"
    }

    // The example runs a multi-line script
    {
        "type": "Button",
        "caption": "Reset",
        "onClick": [
            "SetValue(12345, 0);",
            "echo 'value was reset';"
        ]
    }
Any questions?