Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error encountered: TypeError: Cannot find function getValue in object Generic

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

like image 723
user1503721 Avatar asked Dec 10 '25 09:12

user1503721


1 Answers

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;
}
like image 98
megabyte1024 Avatar answered Dec 15 '25 12:12

megabyte1024



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!