2

I have created a form in Google scripts using an html page, which then calls a javascript function, as documented here. When I run the app, the form loads just fine, but it will not execute the script. How can I make this work?

Here is an example of what I'm trying to do:

<html>
  <!--Create Sign Out Form-->
  <form id="signOut">

    <div>
      Destination: 
      <select name="destination">
        <option value="lunch">Lunch</option>
        <option value="meeting">Client Meeting</option>
        <option value="vacation">Vacation</option>
        <option value="sick">Out Sick</option>
        <option value="personal">Personal</option>
        <option value="home">Working from Home</option>
        <option value="scedule">Reduced Schedule</option>
      </select>
    </div>

    <div>
      Supervisor: 
      <select name="supervisor" onselect="google.script.run.withUserObject(this.parentNode).populate(destination)"></select>
    </div>

    <div>
      Start Date: 
      <input type="date" name="startDate" onselect="google.script.run.withUserObject(this.parentNode).SignOutLibrary.dateSelect()"/>
    </div>

    <div>
      End Date: 
      <input type="date" name="endDate" onselect="google.script.run.withUserObject(this.parentNode).SignOutLibrary.dateSelect()"/>
    </div>

    <div>
      Details: 
      <textarea type="text" name="details" style="width: 150px; height: 75px;"></textarea>
    </div>

    <div>
      <input type="button" value="Submit"
        onclick="google.script.run
             .sendRequest(this.parentNode)"/>
    </div>
  </form>
</html>

And the scripts it should be calling:

function doGet() {
  // Uses html form
  return HtmlService.createHtmlOutputFromFile('request_form');
}

SignOutLibrary:

function dateSelect() {
  var app = UiApp.createApplication();
  var handler = app.createServerHandler("change");
  var date = app.createDatePicker().setPixelSize(150, 150).addValueChangeHandler(handler).setId("date");
  app.add(date);
  return app;
}

function change(eventInfo) {
  var app = UiApp.getActiveApplication();
  app.add(eventInfo.parameter.date);
  return app;
}
Mark Chackerian
  • 21,866
  • 6
  • 108
  • 99
  • any errors in the console? – Prisoner Jun 13 '13 at 15:47
  • not that I've come across yet. (Assuming you are talking about the logger since there is no console :/) – bolensmichael Jun 13 '13 at 15:52
  • I see in the documentation that there is an _onclick_, does anyone know if _onselect_ is supported? – bolensmichael Jun 13 '13 at 16:01
  • Another update: the _onclick_ script for my submit button doesn't reven work? I even tried stting up a completely new library and form from scratch to b sure it wasn't some option I selected and they still aren't running. – bolensmichael Jun 13 '13 at 17:36
  • AFAIK [tag:google-form] is for the Google Forms app not for forms created using the HTML Service for Google Apps Script. This tag should be removed. – Rubén Apr 26 '16 at 12:29

2 Answers2

0

try changing all the this.parentNode in your code with this.form

I quickly looked into the docs and MAYBE it'll work, sorry but I can't test my answer right now

Dariozzo
  • 121
  • 1
  • 3
0

You don't show populate() - hopefully you do have such a function. If you do, then your next task would be to find a way to get a value for destination which you're passing as a parameter. In its present form, it's undefined. See Get selected value in dropdown list using JavaScript?.

You can't call library functions directly using the script runner, see the bit on Private Functions. You would need to add intermediary functions to your "local" gs to interface with the library functions such as SignOutLibrary.dateSelect().

That library uses the UiApp, while the rest of your code uses the Html Service. Pick one or the other, because you can't mix them like this.

Community
  • 1
  • 1
Mogsdad
  • 44,709
  • 21
  • 151
  • 275