Ryan Smith
Ryan Smith

Reputation: 1335

How to get elements that have prefixes in an event with Google Script

I have a function that has this in it.

var obj = app.loadComponent("guiItem", {"prefix": sItems + "-"});

Inside the component guiItem are 2 text boxes (tbx1, tbx2)

I currently have a absolute panel where instances of guiItem can be added, to ensure that tbx1 and tbx2 are unique I prefix the added instance of guiItem each time (see code line above).

The problem: When tbx1 is changed I need the text of tbx2 to change, but I do not know how this can be done with Google Script.

Any ideas?

Upvotes: 1

Views: 90

Answers (1)

Srik
Srik

Reputation: 7957

Try this :

var obj = app.loadComponent("guiItem", {"prefix": sItems + "-"});
/* Store your prefix somewhere */
CacheService.getPrivateCache().put('prefix',sItems + '-' , 300);
/* .... */
var hdl = app.createServerHandler('handleTbx1Change').addCallbackElement('your_panel_object');
app.getElementById(sItems + '-' + 'tbx1').addChangeHandler(hdl); 


function handleTbx1Change(e){
  var prefix = CacheService.getPrivateCache().get('prefix');
  app.getElementById(prefix + 'tbx2').setText(e.parameter.tbx1); // assuming setName('tbx1') on tbx1 

Thats the rough sketch. You'll need to do some fine tuning but that piece of code should show the way

Upvotes: 1

Related Questions