Customer Banners (Ads) - SpiceUp. AX and SpotfireX Disclaimer



If you find this site useful and you want to support, buy me a coffee   to keep this site alive and without ads.

Passing a Javascript value to a Document Property

If I don't have the Javascript API installed, you can assign a javascript value to a Document Property by  using a (hidden) Property Control:

html:
<div id='mySpotfireControl' style='display:none'><spotfireControl id=abc..../></div>

jscript:
//pass javascript property to Property Control
document.getElementById('mySpotfireControl').firstChild.value = myJSObject.property

//same as clicking enter on the input after entering a value on the Property Control
$("#mySpotfireControl input").focus()
$("#mySpotfireControl input").blur()





To pass a javascript value to a multiple line input document property


html

<div id='docPropTarget' style='display:none'>
   <SpotfireControl id="a964447a03cc4b87b6e6495738edb9f6" />
</div>
<br/>
<textarea id='jsValue' >javascript value goes here</textarea>
<div id='btn'>click here to pass js value to doc property</div>



js
$("#btn").button().on('click',function(){
val = $("#jsValue").text()
$("#docPropTarget textarea").text(val).focus().blur()
})


6 comments:

Unknown said...

what is myJSObject in above script

Jose Leviaguirre said...

myJSOObject refrest to an hypotetical jason object with a property to illustrate how a havascript value can be passed to a spotfire document property.

myJSObject could be Math.PI, a javascript function call that returns something or a custom javascript object For example:

myJSObject = {property1:"value1",property2:"value2"}
myJSObject.property1 //returns "value1"

Mr.VapeFly said...

I used the combination of js and jquery in a function passed to a button click event but while in the client app it wroks fine, in the webplayer it crashes with an "interpretation error" and i am quite sure it is because of jquery part of the code:

here is my function:

riskSubmit.onclick = function(){
document.getElementById("hiddenRisk").firstChild.value = document.getElementById("riskarea").value;
$("#hiddenRisk input").focus()
$("#hiddenRisk input").blur()
}

Am I doing anything wrong?

Unknown said...

how to update input field multiple lines using the same . guess there should be some modification done to scripts .

Jose Leviaguirre said...

Interpretation error most of the times means a javascript error, but I believe it was a bug. I haven't seen it in 7.5+

Aaron said...

Hi,

I believe I have found a possible solution/work-around for the issue, entirely based on pure JavaScript (since TIBCO removed jQuery starting from Spotfire X). The solution is to force a simulated Enter Keystroke while focusing the input box to trigger updating the Document Property. (No data function and R needed)

HTML (SpotfireControl Element is an single line input-box for a Doc. Prop.):

< div id="container" >< SpotfireControl id="b8534f13dc62416db6d4eaab16030f5e" />

JS (focus and blur might no longer be needed for this solution, but I'm still keeping them just in case):

var elem = document.querySelector("#container input");
elem.focus();
elem.value = "stringValue";
elem.blur();

const inputConfirmationEvent = new KeyboardEvent("keypress", {
view: window,
keyCode: 13,
bubbles: true,
cancelable: true
});

document.querySelector("#container input").dispatchEvent(inputConfirmationEvent);

Hope it helps someone.

Best,

Aaron