Checkbox property control


With this approach you can have a checkbox that can trigger javascript and python scripts:



The calculated value click action toggles a Boolean document property. When this Boolean doc property changes it triggers the iron python script.

The javascript is triggered by adding a click event handler


Explanation


  1. Calculated value has a custom expression to show a checkbox character marked when document property is on or off:

      If(${booleanDocProp},"☒","☐")

  2. Calculated value has a script associated to run a python script when clicked. The script changes the state of the document property:

    Document.Properties['booleanDocProp'] = not Document.Properties['booleanDocProp']

  3. Another python script changes the visualization title when document property changes:

    //viz is a Visualization type script parameter
    viz.Title = "Checkbox is ON" if Document.Properties['booleanDocProp'] else "Checkbox is OFF"

  4. Optionally trigger a javascript when the calculated value changes.

    cb=document.getElementById('boxyCheckbox')
    cb.addEventListener('click',function(){
      status = cb.innerText=="☒"?"OFF":"ON"
      alert("Checkbox is " + status)
    })

No comments: