0
votes

I will try and keep this brief. I am attempting to make a google web app in google spreadsheet that will allow me to enter a values for min and max.

I have been able to create the GUI and add it to the panel. But I can't seem to pass the integer being entered into another function. I've tried everything, I'm relatively new to creating Google Script so I'm sorry if this comes across as a bit of a noobish problem.

Here is all the code so far :

function onOpen() {
  var ss = SpreadsheetApp.getActive();
  var menuEntries = [];
  menuEntries.push({name: "Open Dialog", functionName: "showDialog"});
  ss.addMenu("Min/Max", menuEntries);
}


//creating a panel to add the min and max of low to high for scoring
function showDialog() {  
  max = 10;
 var app = UiApp.createApplication();
 app.setTitle("My Applicaition");
  var panel = app.createVerticalPanel();
  var textBox = app.createTextBox();
  var label = app.createLabel("Set the min value for 'Low'");
  //had to create a hidden element with id="min" for a global value that can be updated
  var min = app.createHidden().setValue('0').setName('min').setId('min');
  textBox.setName('myTextBox').setId('myTextBox');
  var button = app.createButton('Submit');
  panel.add(label);
  panel.add(textBox);
  panel.add(min);
  panel.add(button);


  //click handler for setting the value of min to the new value
  var clickHandler = app.createServerClickHandler("responedToSubmit");
  button.addClickHandler(clickHandler);
  clickHandler.addCallbackElement(panel);
  app.add(panel);

  var doc = SpreadsheetApp.getActive();
  doc.show(app);
}

function responedToSubmit(e) {  
  var app = UiApp.getActiveApplication();
  var textBoxValue = e.parameter.myTextBox;
    Logger.log(e.parameter.min);
  if (typeof textBoxValue != "number") {
     var num = parseInt(textBoxValue);
     app.getElementById('min').setValue(num);
     Logger.log("textBoxValue is = "+textBoxValue+"\n min value is = "+e.parameter.min);
  } else {
    throw "value needs to be set as number";
  }
  return app.close();
}

This is where I believe things aren't going according to plan :

function responedToSubmit(e) {  
  var app = UiApp.getActiveApplication();
  var textBoxValue = e.parameter.myTextBox;
    Logger.log(e.parameter.min);
  if (typeof textBoxValue != "number") {
     var num = parseInt(textBoxValue);
     app.getElementById('min').setValue(num);
     Logger.log("textBoxValue is = "+textBoxValue+"\n min value is = "+e.parameter.min);
  } else {
    throw "value needs to be set as number";
  }
  return app.close();
}

I find that each time I test the .setValue() will not update the value of 'min' and I cannot see why. Can you please help?

1

1 Answers

0
votes

You need to add textBox element to callBack elements list of your clickHandler. Try this:

//click handler for setting the value of min to the new value
var clickHandler = app.createServerClickHandler("responedToSubmit");
clickHandler.addCallbackElement(panel);
clickHandler.addCallbackElement(textBox);
button.addClickHandler(clickHandler);
app.add(panel);