timer function for xpages xp:messages and hidden input - xpages

I am using a hidden input to store a message for displaying a computed value in a hidden input. I add a message string to the hidden input on postSaveDocument to show the document was saved sucessfully. Being new to this coming from classic Notes development I would like to know how to only have this show for a predetermined amount of time, like 5 seconds, and then go away. So how would I change the value of the hidden input to "" after the time lapse from postSave. Many thanks.

There are many ways to do this. One would be to run this CSJS when there is a message in your input field:
setTimeout('dojo.byId("#{id:divMessage}").innerHTML = ""', 5000);
I didn't quite get which element is showing your message (because you are talking about hidden input) but I assumed it's a div or span.
To set input field value you would use:
dojo.byId("#{id:inpMyInput}").value = ""

Related

Setting Input Value with a Variable at set interval

I have an HTML input text box and I am trying to use Javascript to display a live clock inside this text box (ie. use a script to update the current time every second, and insert this current time into the value=""
To do this, I have a javascript function startTime() running to grab the current time in 00:00:00 format. Then I'm using another function setInputValue() to make the results of function startTime() as the "value" of the input text box
This works and displays the current time inside the text box, as expected.
Since this only displays the time that the scripts were loaded, I need a setInterval() to make it update every second. Unfortunately, adding var t = setInterval(startTime, 1000); does not do it. I've also tried setInterval(setInputValue, 1000); and that does not change the time each second, either.
I'm pasting my code here on this link: https://www.w3schools.com/code/tryit.asp?filename=G1B141Z87FCF
Edit to add: While there are probably easier methods than making the end result the value of an input text box, I am having to do it this way because this "live time" will be displayed as an overlay on a video stream. The only way I have access to editing the text of this video overlay is by changing the "value" of the text box. It all works to display the time, it's just not changing each second unless I manually refresh the script.
Thank you for any help you could provide.

Cognos 10 Report Studio: On Page Prompts & Performance

I have a report page which displays a crosstab. This is filtered by 5 paramaters. These paramaters are submitted by the user through on page checkbox prompts.
The requirement is to return the data with all values in all paramaters selected on the first run. If I leave default selections blank this behaviour is achieved but all the checkboxes are unchecked which gives misleading feedback to the user.
As an alternative I've manually specified all the values in default selections. However, this has a performance impact.
Does anyone have any alternative suggestions?
I've been looking for a way to specifically link a reprompt button to a value list so only those paramaters are resubmitted (rather than the whole page) but haven't found anything yet.
Thanks in advance - even if the answer is 'no and this is a bad way to go about it'!
One option is to use JavaScript to check all of the checkboxes after the page is rendered with no filtering applied. To do this all filters have to be set to optional. The page is rendered with all data and unchecked checkboxes. The JavaScript fires and checks all checkboxes so that the state of the prompts matches the state of the data. This happens so fast the user likely won't know the boxes weren't checked initially. A reprompt button will, when clicked, enforce whatever choices the user makes after that.
Since version 10.2, Cognos has provided a fairly simple JavaScript API to allow for render-time manipulation of prompt controls. Hopefully, you are working with 10.2 or later otherwise the code provided will not work. Here is a bit of JavaScript code that will loop through all prompts and select all values within them:
var report = cognos.Report.getReport("_THIS_");
var prompts = report.prompt.getControls();
if (typeof firstrun == "undefined") {
var values;
for (var i=0;i<prompts.length;i++) {
values = prompts[i].getValues(true);
prompts[i].addValues(values);
}
var firstrun = false;
}
Notes:
All value prompts behave the same way regarding the 10.2+ JavaScript Prompt API. It doesn't matter whether you choose a drop-down, list, checkbox or radio button interface. The way we code for all of these variations is the same. The provided code would work just as well with a list as it would with checkboxes.
Make sure that you wrap your code in script tags and that the HTML Item object you place on your page to hold the code appears below all prompt controls. If it is placed elsewhere it will not be able to find the prompt controls as they will not have been rendered when the code executes.
The code assumes that the only prompts on the page are the checkboxes you want checked. If there are other prompts on the page then you will have to target individual prompts using the getControlByName() function provided in the API rather than looping through all prompts. More information on the Cognos JavaScript Prompt API can be found here.
The key bits of code here are the getValues() and addValues() Cognos JavaScript Prompt API functions. getValues(true) returns a JSON-formatted object representing all values, selected or not, from a value prompt. addValues(values) takes a JSON-formatted object representing the values to be selected and selects them. Thus, it's a matter of grabbing all values and then passing them in to be selected.
The reason for the if block is that we only want this code to run once at first page render. When the user first runs the report we want all checkboxes checked but after that we want the checkboxes to retain state. If we didn't use the if block the user's choices would be overwritten after a reprompt. For more information on this technique check out this tutorial on my blog: JavaScript: Running Code Only Once.
Addendum
If you don't want any filters to be applied when all boxes are checked in a section even after subsequent reprompts you can do so by tweaking your filter.
Assume that we are checking against a model based item [Item1]. We have a current filter of: [Item1] in ?parameter1?. We also have four checkboxes with values of 'Choice1','Choice2','Choice3', and 'Choice4'.
The following modified filter will only apply the checkboxes to the filter when all four aren't checked:
(
'Choice1' in ?parameter1?
AND
'Choice2' in ?parameter1?
AND
'Choice3' in ?parameter1?
AND
'Choice4' in ?parameter1?
)
OR
[Item1] in ?parameter1?
If all four checkboxes are checked then the first part of the OR is satisfied and all rows will be returned. It should be fast too because most languages, including iterations of SQL, will not test the second component of an OR if the first component is satisfied.

Onkeypress canceling event javascript

I have a textbox that I would like to prevent the user from entering any letters in. They need to be able to enter numbers.
The textbox has an onkeypressed event already set, and I'm adding logic so that if the user enters a letter, nothing is shown.
Regardless of what I do (cancelbubble, stop propogation, return false), the letter is still getting entered in the text box. I've watched the debugger go over these and still the letter is being entered, its like it is taking place after the fact of the event.
The event handler hook you are looking for is onkeydown:
yourInput.onkeydown = function(e){
var char = String.fromCharCode(e.which); // get the char
return /[0-9]/.test(char); //assert it's a number
}
working demo
Returning false from an event handler attached directly (rather than attachEvent) cancels the event.
Actually once I got home to test onkeydown was doing the same thing, when I edited what was in the text box, it would still add the non-numeric character at the end.
Ended up using onkeyup, that appears to be far enough down the line that it will wipe out what is in the textbox.
I was really looking for the ajax filtered textbox functionality, but couldn't use that because we aren't using actual ajax controls in the application.

Refresh InfoPath field after code-based calculation

I have an InfoPath 2010 form that creates a new Sharepoint list item. The form has, in essence, one input field and one output field. If something gets entered in the input field then some calculation is performed and I want the result to show up in the output field.As the calculation is somewhat complicated I need to do it in code, not through rules.
private void CalculateOutput()
{
XPathNavigator main = MainDataSource.CreateNavigator();
XPathNavigator service = main.SelectSingleNode("my:meineFelder/my:serviceValue", NamespaceManager);
double serviceValue = service.ValueAsDouble;
double output = 3*serviceValue; // much abbreviated version
// output now has the correct value
XPathNavigator outputNav = main.SelectSingleNode("my:meineFelder/my:output", NamespaceManager);
//Remove the "nil" attribute (otherwise we get an error when the field is a double instead of a string)
if (outputNav.MoveToAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance")) outputNav.DeleteSelf();
outputNav.SetValue(output.ToString());
}
My problem is that everything works fine in the InfoPath preview but once I deploy the form and run it in the browser the output field does not get updated, i.e. I cannot see the result of my calculations.
I have tried .ReplaceSelf (with OuterXML), with zero result. I have also played with assigning the result to another field and thereby firing an "set field value" rule, also to no avail.
If I submit the form, the output value is saved OK but I'd really like the user to see the output field before submitting.
Any Ideas?
Thx a lot.
In case of browser enabled form, ensure that you have set the "Postback Setting" to refresh "Always"
To do this right Click on the control on which the postback is to be triggered. (in your case Service value). Go to Browser Forms tab and set the Postback Setting to Always.

Automatically open document when only one document is listed in repeat control

I have a repeat control for a domino view which displays the results from a search field.
As you type more characters into the search field the number of items in the list is reduced. If/When the the list only contains a single item I would like to open item automatically, without having to click the link.
Any ideas are appreciated.
Edit: after some very interesting responses, here are some screenshots
I have 3 elements on the page, a searchbar, a repeat control and a form:
When I start typing in the search bar, the repeat is refreshed with every keystroke:
the list is reduced, typing the next character ...
again the list is reduced, only 2 left, typing again....
Only one left, now it would be time to open the document in the form ..... without clicking the link.
I've tried several events on the page, but it seems that I could not find the one that will allow me to "select" the document and display the data in the form.
It seems that it's not as simple as I thought
Since you want to open the link automatically I don't know if I would try to base it on the getRowCount() of the repeat itself. You don't want to even get that far right? you just want to go to the single document.
I would put a function in beforePageLoad event maybe. Not totally sure which event but I'd try that first. Use SSJS and do a lookup that would basically return a collection of what the repeat would show. If the collection count = 1 then get your destination from that entry and do your redirection from there.
That what I would try at least. Interesting scenario!
Now that I see the screenshots this might be easier then you think and I have already implemented something similar on an internal application that I have built. It does rely on the fact that each entry in the list is 100% unique.
First of all you will need to bind the search field to a scoped variable and the onchange/onkeypress event will need to perform a partial refresh of a panel that contains both the list and the document portion of the page.
For the list the link on each item should set the value of the same scoped variable used in the search box and clicking the link should be set to run a partial refresh of the document area.
For the document area you will need two panels, the first panel will only display if there is no matching document and the second panel will only display if there is a matching document, you can do this in the rendered section by writing some ssjs that grabs a handle to the db/view and does a dblookup and returns either true or false if the document exists depending on panel your dealing with.
With this setup, when somebody clicks a link or fills out the searchbox the scoped variable will contain a value, the document panels will then check to see if this is a unique value in the view in the db and update themselves to either display the 'no document' panel or the 'document' panel accordingly.
You could add a evaluation script to the entry of your repeat control which checks the size of your repeat control using the method getRowCount() from the component. If this is 1 you could execute a context.redirectToPage("yourpage.xsp?id=yourid",true) this forces the current page to send a redirect request back to the browser and therefore redirects you to the correct page.
All you need to know is which xpage you need to open and which parameters you should use. But these could be retrieved from the content you are iterating over.

Resources