setProperty - Set the value of a variable

This function allows the user to set the value of a variable via a Button to overwrite a specific value . For this, target and value must also be defined. With target, a variable is bound to the state object boundwhich 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 to jump between different pages of a form, such as shown here 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: