getTag() method not properly working for google apps script - google-apps-script

What i am doing in writing a script that lets the User interact with a data table. Every series that the user chooses creates a button, and then plots the series on a graph. if the user click the button it rooms the series. All there the data is stored in a hidden JSON string. the columns, or series that the user whats to see are stored in an array that i call index, it is also a hidden JSON string) Each button is connected to its own client handler, which has a
.forTargets(the index i was talking about).setTag(to the corresponding column in the data array)
and they are all connected to the same server handler. So when the button is clicked the client handler sets the tag for the index to the series that it is supposed to be removed. Now the server handler will run it get the index by ID and get the Tag. This is were it goes wrong. The tag is always null.
The first thing i tried was to see if my client handler was not working properly. So i set the tag of the index to some number, but the getTag method in the Server handler still returned null.
idk, but maybe Tags are not saved in the UI instance??
Below is the first bit of the Server handler.
function clickServer(e) {
e = e.parameter;
var app = UiApp.getActiveApplication();
var master = JSON.parse(e.dataTable, "reviver");
var index = JSON.parse(e.index, "reviver");
var hidden = app.getElementById("hiddenIndex");
var tag = hidden.getTag();

I think the issue you are meeting is more related to timing : handlers are called simultaneously, this is true for client an server handlers as well, that means that if the client handler changes a hidden tag value this change happens too late for the server handler function to 'see' it. What you should do is create a separate button to trigger the server handler that the user would use after all the other parameters where set.
This very same method is used in the known workaround used to get radioButtons value
Also, why do you use tags on the hidden widget ? you could use it with direct access by setValue() and e.parameter.hiddenName since they are already invisible by nature... ?
Note also that you can set a value in client handlers as long a these values are defined inside the Ui instance (the do Get function) either by constant variables or by another client Handler in the same function, as shown in the before mentioned example with radioButtons... but that's only a detail.
In this context if you need to get a widget value (inside the doGet function) you should of course use getValue() to get the widget value as no e.parameter is available at this time.
I hope I've been clear enough, re-reading this I'm not very sure but.... just ask if something is missing ;-)

The tags values are passed to handlers via parameters. In this post this fact is explained in details.

Related

A way to require dbc.Input to receive an updated value before triggering a callback while using debounce?

I have a large, dynamic number of dbc.Inputs (~200) that trigger a callback.
Their id’s use pattern matching callbacks.
The value entered in the input updates a SQL db.
The problem I am facing:
I need to have debounce=True so that every keystroke doesn’t trigger the callback.
However, having debounce=True also makes it so that if the Input is clicked into, and clicked out of without any changes being made, it still triggers the callback.
Is there any way to make it so the callback only triggers if the current value has been changed? I was hoping this could be done within the args of the input itself but did not see any args that would achieve this.

ColdFusion convert hidden form variables to a structure

The app I am working on has hidden input variables set on initial load of the page. The variables need to be accessed across all pages. The reason for not converting these to session variables is the user can open another browser with different parameters and passing those value as hidden inputs make it work without any issue. What is the best possible alternative so as to get rid of these hidden inputs..I tried converting all variables into a Structure, but again the structure needs to be posted as part of form submission to make it available to subsequent pages.Another disadvantage of this app is use of frames.I don't have any code to post.
It sounds as if you want different browsers instances which are associated with the same web session to maintain their own distinct sets of data. Doing this by passing form or url variables around seems like a bad idea.
One approach that you could use would be, onSessionStart (or as required), create a structure in the users session to hold instances of the data. For example
session.data = {
someRandomKey: {
valueA: 42,
valueB: "Porridge"
}
}
Then just pass someRandomKey as a hidden form field or querystring parameter. Now, when they submit the form to update variables you use the id from the hidden form field to find the appropriate structure from session.data.
When the user needs a new instance of this form, give them some way, like a link or button, that creates a new unique key, inserts a struct in session.data with this key and populates it with whatever defaults are needed then loads the form passing along the new id as a hidden form field or querystring param again.

how to bind input text and combo box in angularjs 1

I have two controls in a form.
zip code - (input type text) and city - (select options)
The back-end rest service sends json object which will contains zip codes and city names. I want to change city when zip code changed and vice versa using angularjs1. Also validate zip code with json object.
please help me...
Alright. So I am assuming that you have a serverside script from which you can get both city from pincode and pincode from city
Now you have got 2 controls in your view.
1) Input Box
2) Combobox
Now The easiest way according to me is that you should make a function that is called on ngChange event of both the controls.
That function would make a request to your server and fetch the associated data and feed the data to the other control.
Now when you populate the controls internally through the controller, it might again fire an ngChange function. So in each ngChange function you must have a reference of the desired values for them. That can be done by storing both the latest values received from server side into a local variable and checking it each time the function is called.
I believe this would solve your problem.
----------------Update----------------
As mentioned in the comment, the SPA shall not be sending request to the server during the execution. It shall simply send the json at the end.
So for that its more convenient. Simply make 2 different functions, 1 getCityFromPincode(pincode) and 2 getPincodeFromCity(city)
Now you can easily do your operations in javascript on the basis of the values that you will get from the ngChange() function.
Just call the function getCityFromPincode in the ngChange function of your CITY INPUT Control and similarly for the other one.
You would probably make it through with this approach.

How to replace chrome.tabs.onSelectionChanged deprecated method?

I need to get data from the tab the user is leaving (switching on other tab or going on other program).
But chrome.tabs seems not providing an event allowing that..
Before there was apparently chrome.tabs.onSelectionChanged (not tested) but it's deprecated.
And other event are giving the data of the new tab not the one the user just left...
I try also jQuery $(window).blur event, but i have to make a call to the chrome.storage of the tab left by the user (i create a storage for each tab named by the tab id) and i did not get the response of storage in time with this event (the result of the storage is used in a if() to know if i have or not to display an confirm box.
Someone could help me ?
Thx !
To detect a tab change, just use chrome.tabs.onActivated. Since you're interested in the previous tab, store the result of the event at the end of each event. For instance, like this:
var storedWindowInfo = {};
chrome.tabs.onActivated.addListener(function(activeInfo) {
var windowLastTabId = storedWindowInfo[activeInfo.windowId];
if (windowLastTabId) {
// Do something with previous tab, e.g. send a message:
chrome.tabs.sendMessage(windowLastTabId);
}
// Update ID of currently active tab in the current window
storedWindowInfo[activeInfo.windowId] = activeInfo.tabId;
});
Note: Only the tabID and windowID are provided to this event. You need to issue chrome.tabs.query to get more information, such as whether the tab still exists, its URL, etc.

How to know which element called the callback function?

I have a script creating buttons in a table.
Each button is assigned to the same callback server function.
My question is how do I know which of these buttons triggered the server call?
Also is there a way of outputting a msgbox from the server script? When I try browser.msgBox, it gives an error saying that msgbox can't be used in this context.
var clientDel = app.createServerHandler("delStudent").addCallbackElement(grid);
table.setWidget(t, 4, app.createButton("Delete", clientDel).setId("del1"));
function delStudent(e){
var app = UiApp.getActiveApplication();
e.
return app;
}
Thanks,
C Singh.
simply e.parameter.source will return the ID of the widget that originates the handler function
You can use a label or a textBox that you create in your UI and set invisible. Then at any moment you can use getElementById(label_ID').setVisible(true) and put any text in it.
If you want it to appear at a specific position above all other widgets you can do that quite simply using setStyleAttributes, see this other post(server version) for further info and practical example