setProperty - Set the value of a variable

This function allows the user to overwrite a certain value via a button . For this, target and value must also be defined. With target, a variable is bound to the state object, which is changed according to the value in value.

Example

In the following simple example, the use of setProperty is shown. Practically, this function can be used, among other things, to jump between different pages of a form, as shown here.

setProperty.json
{
  "$schema": "http://bpc.virtimo.net/forms/1/schema",
  "metaData": {
    "id": 0,
    "version": 0
  },
  "components": [
    {
      "type": "container",
      "label": "setProperty Example",
      "components": [
        {
          "type": "html",
          "value": "'<p>Current value of variable: ' + /data/someValue + '</p> New value of variable after click on subtract: ' + (/data/someValue - /data/subtractValue)"
        },
        {
          "type": "numberfield",
          "label": "Changeable value of variable",
          "value": "/data/someValue"
        },
        {
          "type": "numberfield",
          "label": "Input value which is subtracted from above variable if subtract button is clicked",
          "value": "/data/subtractValue"
        },
        {
          "type": "button",
          "label": "Increment",
          "action": "setProperty",
          "target": "/data/someValue",
          "value": "/data/someValue +1"
        },
        {
          "type": "button",
          "label": "Subtract",
          "action": "setProperty",
          "target": "/data/someValue",
          "value": "/data/someValue - /data/subtractValue"
        },
        {
          "type": "button",
          "label": "Set to 1",
          "action": "setProperty",
          "target": "/data/someValue",
          "value": 1
        }
      ]
    }
  ],
  "configuration": {
  },
  "state": {
    "data": {
      "someValue": 5,
      "subtractValue": 3,
      "readOnlyVariable": true
    }
  }
}
Embedded preview

Keywords: