Escribir Casting en Apps Script

First time on StackOverFlow!

I am working on building an app that takes in a value through a UI Form TextBox. Once that form is submitted it calls a method that then appends a "/" to the value. The problem is that .append() is not available, because getElementById() returns a GenericWidget object and thus cannot be operated on as if it were a string. I have tried type casting it use .toString() in the var userinput = app.getElementById('input').toString; call and afterward using userinput = userinput.toString.

I have been working with Apps Script for about a month and a few days now and I think that casting to a different type other than GenericWidget would be helpful for anyone who wants to modify a value in a type specific way after passing the value to another method.

I have also done a good bit of research trying to find a solutiong for my problem but like a couple times in the past working with Apps Script I find that since it is a younger language there isn't as much helpful information as there is with languages like Javascript, HTML, and XML. Any help is appreciated.

preguntado el 31 de julio de 12 a las 14:07

1 Respuestas

You have to get the textBox value using e.parameter.textBoxName an then re-assign a value to the textBox. A short example will be more explicit

function doGet(){
 var app = UiApp.createApplication();
 var textbox = app.createTextBox().setName('txt').setId('txt')
// add other elements, handlers, callBackElements, etc...

function changetext(e){
var app = UiApp.getActiveApplication();
var textBoxValue = e.parameter.txt ; // get the value in the text box
var txtBoxWidget = app.getElementById('txt') ; get the widget by its ID
txtBoxWidget.setText(textBoxValue+'/'):// assign the modified value
return app ;// update the UI with new value

Respondido 31 Jul 12, 20:07

Awesome. I didn't think to pull the parameter directly from the box. I've just been dealing with passing things by ElementById(). Thanks a ton! - Jared Garcia

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.