In this example, we want an Action Control Button that will toggle some Boolean Document Property. The state of the Document Property will be shown as the label of our Button Action Control.
To rename the button with a Document Control Value, put a Label Property Control on a Text Area next to your Button Action Control. Make sure you have a Document Property called 'toggle' set to False
html:
<DIV id="myProperty" style='display:block' >
<SpotfireControl id="465a3...." />
</DIV>
<DIV id="myControl">
<SpotfireControl id="c05eba...." />
</DIV>
note: you can hide the label by changing display:block to display:none
javascript (newer verisons)
//get the document property value
myProperty=$("#myProperty").text()
//rename the button (you can change other properties too)
control = $("#myControl input")
control.val(myProperty)
javascript (older version):
//get the document property value
myProperty=document.getElementById("myProperty").innerText
//rename the button (you can change other properties too)
control = document.getElementById("myControl").firstChild
control.value = myProperty
//control.style.width = "100px"
//control.style.backgroundColor = "red"
//control.style.color = "yellow"
To change the document property and then trigger the javascript, via iron python, then use this code on the Action Control button:
#toogle the Boolean Document Property
Document.Properties["toggle"] = not Document.Properties["toggle"]
#Trigger the javascript on the text area after clicking
from Spotfire.Dxp.Application.Visuals import HtmlTextArea
vis.As[HtmlTextArea]().HtmlContent += " "
8 comments:
Could you please let me know, how to get the output, I tried my best but did not get the desired result. Please help me, when I try to copy the Java Script my Label is disappeared. Another problem, I am getting an exception with Iron Python script. Here is the short detail: Microsoft.Scripting.Runtime.UnboundNameException: name 'vis' is not defined
at IronPython.Runtime.PythonContext.MissingName(SymbolId name)
at Microsoft.Scripting.Runtime.LanguageContext.LookupName(CodeContext context, SymbolId name)
'vis' is a Script Parameter that points to your text area visualization
Thanks, Jose
I appreciate for your help
Can you help, I get an Iron Python error: Microsoft.Scripting.Runtime.UnboundNameException: name 'HtmlTextArea' is not defined
at IronPython.Runtime.PythonContext.MissingName(SymbolId name). Thanks in advance.
you need to add from Spotfire.Dxp.Application.Visuals import TablePlot, HtmlTextArea at the beginning of the python script
Is this still working in new version of Spotfire? I tried in 7.8 and no success.
hi Vojtěch,
Thanks for your comment. Yes, seems that the design architecture changed on the back end. Try using jquery in your javascript to get the values of your elements:
change:
myProperty=document.getElementById("myProperty").innerText
to:
myProperty=$("#myProperty").text()
and :
control = document.getElementById("myControl").firstChild
control.value = myProperty
to:
control = $("#myControl input")
control.val(myProperty)
I updated the post
Thanks Jose, you are maestro :-) .
Post a Comment