3

I'am very new to google-apps-script. I encounter this error "TypeError: Cannot find function getValue in object Generic" that i can't figure out why.

Here is the code :

function doGet(e) {


  var app = UiApp.createApplication();
  app.setTitle("My first application");

  var vPanel = app.createVerticalPanel();

  var hPanel3 = app.createHorizontalPanel();
  hPanel3.add(app.createLabel("Text"));
  var textArea = app.createTextArea().setId('theText').setName('theText');
  //textArea.setName("textArea");

  hPanel3.add(textArea);
  vPanel.add(hPanel3);

  var hPanel4 = app.createHorizontalPanel();
  var button = app.createButton("Save");
  var handler = app.createServerHandler('onClick');
  handler.addCallbackElement(textArea);
  button.addClickHandler(handler);
  hPanel4.add(button);
  vPanel.add(hPanel4);

  var label = app.createLabel().setId('label').setText('tata');
  //label.setName("label");

  var hPanel5 = app.createHorizontalPanel();
  hPanel5.add(label);
  vPanel.add(hPanel5);

  app.add(vPanel);

  return app;

}

function onClick(e) {
  var app = UiApp.getActiveApplication();
  // ERROR occurs here when the button is clicked
  var text = app.getElementById('theText').getValue();

  Logger.log(text);

  app.getElementById('label').setValue(e.parameter.textArea + ' toto');
  //label.setText(textArea.getValue());

  return app;
}

I've already change the name and id of the textArea but nothing works.

Thanks for your help!

Trung

1

3 Answers 3

4

The TextArea class has no the getValue method. Its value is passed to a handler as a parameter. Here is a sample demonstrating how it works.

function doGet(e) {
   var app = UiApp.createApplication();
   var panel = app.createFlexTable();
   panel.setWidth('100%');
   var btn = app.createButton().setId('btn').setText('Click Me');
   var textArea = app.createTextArea().setName('textArea').setValue('Text');
   var handler = app.createServerHandler('onBtnClick');
   handler.addCallbackElement(panel);
   btn.addClickHandler(handler);   
   panel.setWidget(0, 0, btn);
   panel.setWidget(1, 0, textArea);
   app.add(panel);
   return app;
}

function onBtnClick(e) {
  var app = UiApp.getActiveApplication();
  var btn = app.getElementById('btn');
  var textAreaValue = e.parameter.textArea;
  btn.setText(textAreaValue);
  return app;
}
Sign up to request clarification or add additional context in comments.

1 Comment

I though that it should have getValue or getText method in TextArea. I already attached addCallbackElement directly to the text area but it did not work. It works now when i use the parent panel instead. Thanks for your help.
2

Change

var text = app.getElementById('theText').getValue();

by

var text = e.parameter.theText;

e is your form value
you use the name fixed with setName to choose which parameter of e you want to get in the variable

Comments

1

If you refer to the documentation for textArea, there is no such method as getValue() for textArea. As Cartman answered you can get the value through the callbackElement which uses the name of the textArea as parameter (the ID is not necessary unless you want to setValue() with something else)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.