How to get text from textbox in GAS? - google-apps-script

I run my GAS as an Apps-script-gadget on my web-page and use the GUI-builder. I have two questions:
1.
I know how to set text in a textbox:
app.getElementById("TextBox1").setText("BigSister");
But how do i get text from a textbox?
I tried:
app.getElementById("TextBox1").getText();
...getValue();
...value;
etc.
Nothing works...
2.
Is it possible to print a message window from the code to the screen f.Ex. for debugging purposes?
Any advice would be appreciated.

Within your handler code, you can access the value of the text box as
var value = e.parameter.TextBox1 ;
Before doing this you must have run the setName() method on your text box.
var tetxbox1 = app.createTextBox().setName('TextBox1');
I suggest you run through some of the tutorials at https://developers.google.com/apps-script/articles where you can find answers to many of your questions.

You can retrieve the value of your ListBox when it is passed back through a handler. It's passed in the parameter class under the Id of the ListBox. The following is a fool-proof method of retrieving that value:
function changeHandler(e)
{
var source = e.parameter['source']; //source is your Id of the element
var value = e.parameter[source]; //value is the selected item as ['a' | 'a,b,c']
//More code here
}
I'm still waiting for a solution to retrieve that value without a handler.

EDIT here is a workin example for you to test
online test
and the script + GUI is here
=======================
Srik answer is absolutely right - as usual ;-) - but to make things a bit more clear to you since you are using GUI builder here is a small screen capture that shows the relevant parameters.
As for your second question, the simplest thing to do to get a momentary showing window to 'print' some data to screen is to use a texBox or a textAreal (or anything else that allows to show text...) and play with the setVisible(true) & setVisible(false) to show/hide the widget. In the GUI builder you can put it anywhere in your UI, even over other elements that you normally use since it will be invisible most of the time (the visibility parameter is available in the GUI builder environment as well). It will behave exactly as a 'popup' in other environments...

Related

How to Set Value of Image from one form to another via VBA code

When i wanna set value of photo from one form to another form through VBA code using this:
Forms![EMP_GRID]![USERPHOTO].Picture = Forms![EMP_PASS_MASTER]![PHOTO].Picture
or
Forms![EMP_GRID]![USERPHOTO] = Forms![EMP_PASS_MASTER]![PHOTO]
or
Forms![EMP_GRID]![USERPHOTO].PictureData = Forms![EMP_PASS_MASTER]![PHOTO].PictureData
It shows an error object does not support this property or method.
I have used all these but, i don't know how to set value of photo or image.
Please anyone can help me
This is something you should have been able to Google pretty easily, I assume that's why you've received downvotes. (You didn't give a lot of information about your question either)
Me.ImageControl.Picture = Forms!MyOtherForm.ImageControl.Picture

Get value of textbox in a table (GAS)

I know that this is something discussed sooo many times, but I can't get the value of a textbox that is placed in a table. I know how to get the value of a textbox (e.parameter.textBoxName), usually it's working without any problems.
The only difference now is that I have a gadget containing 5 tabs, each with some intro text and a table. Each table contains approximately 30 rows, each with two textboxes and a button to submit the value of two textboxes in the specific row to a spreadsheet. Everything is working fine, all the names (and IDs as well) are unique, but the problem is that when I submit textboxes, I get "undefined" (in my spreadsheet).
I guess the problem lays somewhere in the complexity of the script, so this:
function buttonClick(e) {
var app = UiApp.getActiveApplication();
var theValue = e.parameter.textBoxName;
...something...
}
..is simply not enough to define which textbox it is. However I'm getting the button ID without any problem with
var buttId = new String(e.parameter.source);
I'm trying to get my head around this for a couple of days without any results. I'm not that good with GAS and I'm completely out when it comes to objective programming. Do you have some ideas how to get this value? I can get the ID of the table if that helps, but what to use then?
Thank you very much in advance!
EDIT:
I tried .addCallbackElement(textbox) to the textbox - I'm getting an error. I tried .addCallbackElement(textbox) to the submit button together with .addCallbackElement(button) and I'm still getting "undefined".
the callbackElement must be added to the handler, not to the widget nor to the button.
The easiest (and safest) way to get it done correctly is to choose the highest level parent as callbackElement.
I your case it would probably be the tab panel or eventually another panel that contains your 5 tabs if you used one.
Note also that there might be really a lot of widgets in the same UI without causing any issue... I have an app with about 200 textBoxes that works flawlessly and I'm not aware of any limit nor if a limit even exists...

Get TextBox Value from Google Apps Script

I am new to the world of Google's Apps Script, and I am trying to create a basic UI for my end user to query data (stored in google spreadsheets) and display the data in a formatted / user friendly way.
Since I want to start off simple and add in components as I learn Apps Script I decided to create a basic form that will allow me to enter text in a text box, then assign that value to a label (what I thought would be a simple exercise in creating basic form components, and retrieving / assigning values).
Unfortunately the stumbling block I ran into is that there is no getText() or TextBox.getValue() function. I tried searching through online forums / google etc to find out the way around this, but nothing I try seems to work (previous searched led me totry and work this out in an event handler).
My question is this. If I have a textBox ('textBox1') and a button ('button1') and a label ('label1'). How to I get my web app to assign the value I enter in textBox1 to label1 when I click button1?
I realize this is probably the most basic of questions, and I know it has been asked before....but no matter how hard I dig through these old posts I can't seem to figure what should be an easy bit of code out.
Thanks in advance.
Suppose you have code that looks like this:
var textbox = app.createTextBox().setName("textboxName");
var buttonHandler = app.createServerHandler("updateLabelText").addCallbackElement(textbox);
var button = app.createButton("Click me").addClickHandler(buttonHandler);
var label = app.createLabel().setId("label");
Then in your function:
function updateLabelText(e) {
var app = UiApp.getActiveApplication();
app.getElementById("label").setText(e.parameter.textboxName);
return app;
}
So the things to note:
The button handler is given the name of a function that you define somewhere else in your code.
The button handler also must be given a "callback element". This is required if you want to read the value of that element in your function. You can add a panel as a callback element and anything that's on that panel will be added to the callback.
Values of callback elements are passed back through e.parameter. The property name is the name of the element. Example: e.parameter.textboxName.
The label needs an ID so that you can reference it from your other function.

Flex TextInput with default mobile skins automatically regains focus on callout close

I'm working on a simple auto complete function for my Flex mobile app. For that I've got a CalloutButton that triggers a Callout.
The Callout holds some lists from which the user can select items. On item select, the callout gets closed (calloutButton.closeDropDown()).
The very same behavior is done for a TextInput. The user inputs text, the callout opens and according to the entered text, the lists change. Works fine so far. Now, when the user selects an item from any of the lists, the callout closes. Also fine.
Now the issue, after the callout is closed, the TextInput automatically regains focus.
On a mobile device this is more than disturbing.
I narrowed this behavior down to the mobile TextInput skin (spark.skins.mobile.TextInputSkin) since a TextInput without this skin class doesn't show this behavior.
Now you might say just use the default skin instead but unfortunately I can't. The default skin has a bug with Android devices that doesn't pass though the enter event. That I could live with since I'n not necessarily dependent on the enter event, however, the spark mobile skin allows be to continue entering text in the TextInput even after the callout has been opened, which is desperately needed as the lists change according to the entered text.
I can't provide any code as the problem has been narrowed down to the skinClass, thus should not be in my own code. Believe me, I tried every nice and not so nice method to prevent the TextInput from getting focus again, but nothing worked.
So, totally stuck here!
Hopefully you guys have some ideas on how to solve this.
Edit:
Below the steps of my application's behaviour. (to be fair, the workflow inside the callout is a little more complex, I'm working with several lists and a SplitViewNavigator here (thus can't use the Flextras autocomplete), but that doesn't affect the TextInput focus issue I'm facing).
Enter text in TextInput
On key change a Callout with two Lists is opened.
The first List receives results according to the entered text from a webservice
User selects item from list
Second list receives results according to selection from first list from webservice
User selects item on second list
Callout closes
This all works fine, except that the TextInput receives focus after the Callout closes.
I really don't know what triggers this behavior.
Edit2: Code to further illustrate the issue.
Naturally, this is stripped down to the very basics, but it mirrors the behavior of the component and focus.
First the CalloutButton and TextInput that can both control the Callout:
<ui:SearchCallout id="detailSearch"/>
<s:TextInput id="searchInput" skinClass="spark.skins.mobile.TextInputSkin"
enter="historySearch(searchInput.text)"
focusOut="searchFocusOutEvent(event)"
focusIn="searchFocusInEvent(event)"/>
The TextInput's focus handlers don't do anything related to the callout, they just set current states of another component, so I'll leave them out here.
Function historySearch closes the CallOut (I forced it to close as it wouldn't close with the usual closeDropDown()), formats the search text, handles a searchHistory and eventually triggers the search function that passes the formatted search text to the selected component.
Here are the parts that matter for this case:
private function historySearch(val:String):void {
detailSearch.forceClose=true;
detailSearch.closeDropDown();
searchEvent(_searchSyms, true);
}
Note: 'val' (the TextInput's text) is trimmed and whatnot, eventually it will result in an array of strings, represented by '_searchSyms'.
Further eventListeners are as follows:
searchInput.addEventListener(KeyboardEvent.KEY_DOWN, onKeyEvent);
searchInput.addEventListener(FlexEvent.VALUE_COMMIT, onKeyEvent);
searchInput.addEventListener(TextOperationEvent.CHANGE, onTextChange);
KEY_DOWN and VALUE_COMMIT don't have anything to do with the Callout, they are used to handle stuff for the searchHistory, hence I'll leave the onKeyEvent function out here.
onTextChange triggers the string search on the server and closes the Callout in case the TextInput's text is an empty string:
private function onTextChange(event:Event):void {
if(searchInput.text=="") {
if(detailSearch.isDropDownOpen) {
(detailSearch.rightView.activeView as RightView).clearDetailList();
detailSearch.isCloseable=true;
}
}
_searchManager.getRicsByChar(searchInput.text);
}
Eventually the server will respond and passes an array of responses. The Callout gets opened and it's lists are filled with the responses.
I won't paste all the Callout content's code here as it would be way too much. Basically, the user selects an item from any of the lists, the Callout is forced to close and the search function that passes the value to the component (not yet pasted here, be patient ;), is given the item's value. That basically looks like this (never mind the FlexGlobals stuff, this gets all refactored once the focus issue has been resolved):
var search:String = String(event.currentTarget.selectedItem);
FlexGlobals.topLevelApplication.detailSearch.forceClose=true;
FlexGlobals.topLevelApplication.detailSearch.closeDropDown();
FlexGlobals.topLevelApplication.searchEvent(new Array(search), true);
Allright, now the final step of the whole functionality, the searchEvent. As already said, this function basically only passes the formatted search value to the selected component. This either happened on 'Enter' of the TextInput (as the code above shows), or on selection of an item from one of the Callout's lists.
public function searchEvent(_searchSymbols:Array, setText:Boolean):void {
if(setText) {
var _searchString:String="";
for each (var _sym:String in _searchSymbols) {
_searchString += _sym + ", ";
}
searchInput.text = _searchString.substring(0, _searchString.length-2);
}
stage.focus=null;
if(selectedWindowContainer) {
// set the array of search items to the selected component here
selectedWindowContainer.setFocus();
} else
trace("[MAIN] no component selected");
}
And that is basically it. This function is the last step of my search routine, and the selected component (that will get the search items), is getting the focus.
Yet, it automatically loses focus again and the TextInput will receive it. I have no idea where and why this happens, and I need to get rid of this behavior asap!
Wow, what a post, anyone still reading this? ;) Well, I hope so.
Well, after hours of testing several ways to prevent the TextInput from automatically gaining focus, I (kinda) solved the issue, although I think it's more a dirty hack than anything else.
Setting the TextInput's focusEnabled to false works fine, even though the focus indication (border around the TextInput) won't work with this any more (an issue I can live with for now).
Still, I'd really like to know what exactly is going on here, especially in the mobile skin class.

Populate a registration form with Tab Delimited Data

I have a Tab Delimited Data lets say Name Address DOB EmailID copied to clipboard, now I need to paste this data on some online html forms which contains these fields,but whenever I am trying to do so its pasting all the contents in selected text box, where as if I try the same in excel its recognizing the tabs and placing each filed properly in a different cell.
Do I need to format my input data some other way, please let me know.
It's a little bit difficult to tell when someone pastes data into a field. I believe that only IE and Safari support the onpaste event [source]. For everyone else, you could just check the keypress event.
Anyway, if you can find an appropriate event to latch onto, just check the value of the element, and if it contains tab characters, split the value on that and populate the remaining fields.
document.getElementById('first_field').onpaste = function() {
var cells = this.value.split('\t');
if (cells.length > 1) {
// loop through 'cells' and put the value into the other fields
}
};
I'm not sure this is possible without a bit of programming (creating html forms to post), I wouldn't normally recommend it but if you are not familiar with any programming constructs you might want to check out autohotkey, you might be able to get it to mimic your copy and paste action. If you want a real solution, just holler.