Invoke javascript on the change of a document property via a python script - spotfire

Usecase - There is a python script which changes the value of an input field property control(say input1). Need to invoke a javascript whenever this document property(input1) changes. Tried using the change event in the javascript but it does not trigger the javascript. The javascript triggers only if we manually set a value and click in the text area to submit the value.
Has anyone found a workaround for this? Using Spotfire version 7.0

I have successfully done this by adding a space to the html in the text area via the IronPython script.
#add a space to trigger JavaScript
from Spotfire.Dxp.Application.Visuals import HtmlTextArea
txt.As[HtmlTextArea]().HtmlContent += " "
txt is an input parameter of type Visualization. Make sure this is the Text Area visualization where your JavaScript is that you wish to trigger. If you place this at the end of the python script that is updating the property control it should trigger the JavaScript as it re-renders the Text Area visualization. Hope this helps!

Related

Is there a way to get the ID of the textbox created by ZeppelinContext's z.input

I have a spark based note in Zeppelin, where by using Javascript I want to modify the text in a text box created through Zeppelin's z.input. Is this even possible? I mean, can I get the ID of such a texbox so that I can modify its value through Javascript's HTML DOM functions.

Can't open Xpages Dialog from a client-side included script

It seems the only way to open a client-side dialog is from within an embedded control which doesn't work for me. Most of my coding to populate the dialogs is contained in an external script library, yet when I try to XSP.openDialog(id) I receive a jumbled javascript error on Firebug.
I have tried
Accessing the object (an extension library dialog) directly from a button on the xpages. It opens without a problem
Calling a script function from an embedded button and passing the id of the dialog. Error.
Created a global variable containing the id of the dialog and called directly from a button. WORKS
Same global variable, but called in a javascript function. ERROR
from within script created variable with dojo.byId. ERROR
Is there something else I need to configure? Many of the buttons I will be using are also dynamically generated from a JSON-supplied feed.

limit number of characters entered in cognos search and select prompt

limit number of characters entered in cognos search and select prompt
`The below script works for text box.
<script>
// The ASDF here comes from the Name property of the prompt
var fW = (typeof getFormWarpRequest == "function" ? getFormWarpRequest() :
document.forms["formWarpRequest"]);
fW._textEditBoxASDF.maxLength = 3;
</script>`
I need a similiar piece of code to work with Search and select prompt.
I don't have cognos in front of me but let me tell you how i did stuff like this with Javascript. Please read entirely as there are several approaches.
Put a uniquely named/id DIV tag around your native Cognos select and search prompt(The one your typing in. This will make it easy to reference with Java's dom model for the next steps. We will eventually make this default search prompt invisible/hidden but for now keep it visible until the following steps are coded/debugged.
Create an HTML control in the simliar style as the native Select and search with the proper max-length settings that you want. Use the text box on change event to update the native Cognos select and search prompt. for debugging troubleshooting i find it handy to have javascript alert the DIV innerHTML so you can see whats under the hood with the Cognos control. Sometimes i uses this innerHTML as the starting point for my "Cloned/Shadow" HTML prompt that i have control over.
Once you have your new HTML control effectively changing the Cognos control you can make it invisible.
On complex dashboards/scorecarding i wrote routines to clone cognos prompts and expose their HTML so i could create my own control that would quietly manipulate the actual hidden controls. This gave me complete control over presentation and functionality.
There are many variations on this once you have the controls innerhtml like replacing the innerHTML with one of your own immediately after the page loads that has the restrictions on length. Or simply seeing if you can massage the property learning from the innerhtml.
In Cognos 8.4 and 10 there is a new method to dynamically add a method to a control to be called prior to any other methods. It is tricky but it is on IBM's web site. I may be more cleanly implemented in 10 and also IBM is not shy about showing off these solutions on their web site.

Custom Control datasource use in Xpage

How can I use a custom control datasource (named doc) in XPage Application layout?
I need to control read mode and edit mode through the basic node of the place bar.
When I put the code doc.isEditable() in the rendered property, the following error is display in the browser:
Error while executing JavaScript computed expression
Script interpreter error, line=1, col=6: [ReferenceError] 'doc' not found
JavaScript code
doc.isEditable();
I am new to Xpage.
Can you post some code? not entirely sure what you mean.
Generally the best place to define a data source is at the top of the XPage so that every control beneath it has access to it. If your defining a data source after your trying to query it you would get an error like this

Pre-loading browser clipboard for testing pasting into fields with watir-webdriver

Our web application has some event code to "format" any text with pasted into a field so that any HTML styles do not break our data.
What would be a good way to pre-load the browser clipboard so that I can test pasting into the input field?
Is there any way to do it programmatic-ally or would I have the test script visit "a source page" and copy text before moving onto our application?
Any ideas or code snippets would be welcome.
Working with the clipboard will depend on your platform. E.g. on OS X, you can use pbcopy and Command-V:
open('|pbcopy', 'w') { |io| io << 'some text' }
browser.text_field(:name => 'q').send_keys([:command, 'v'])
I know there are equivalents on Linux (xclip?). Not sure about Windows.
I would consider using the .value= method to set the value. If it's been implemented the same as in watir, then it causes no events to be fired and sets the value directly, and then follow that up by sending an appropriate event (depending on what if any events are being monitored) such as onKeypress. I tried to figure out from the Watir-webdriver rdoc for textfield, if this distinction between .set and .value= has been maintained, but the way the doc describes them (at least there) makes them seem interchangable.. (Jarib can you clarify???)
Potentially you might need to first fire something like onFocus depending on the controls you are using. For example, as described in this SO case Setting a text field that has a JQuery mask on it for a jquery mask, they had to end up firing an unmask event to be able to even set the field.
This is a good case for utilizing the techniques described here How to find out which JavaScript events fired? and in the SO item linked in the comments for that question, to figure out just what events are fired when you manually paste something into a field. (note I would slueth it with both using the mouse, but also using something like tab to move between fields and set the focus, events common to those two methods are the ones most likely to be implemented by the controls.
I presume you have some kind of client side javascript that needs to check what was pasted into the field, and thus the reason for this test. If you are using standard HTML fields, with no javascript stuff, then I would consider this particular test case to be effectively the same as 'testing the browser' since supporting cut and paste in input fields is a standard browser function. In that case, you are sort of 'off the reservation' and I'd not bother with such a test case.

Resources