GAS Evaluate field before post Google Form
<p>I have a Google Form with a text field inside.</p>

<p>I want to evaluate the content typed by the end-user before doing the post, but after a few days of searching I have not been able to do it.</p>

<p>In the <code>code.gs</code>, I am able to access the text field and grab the properties of it. If you see the <code>sdi.html</code>, this triggers the call of the function <code>doEval()</code>.</p>

<p>My issue is that I don’t know how to add a handler in the Google Form itself so that I can check that the content of the text field is something acceptable to my app. For example: validate it if this is a number and if this is true then submit the form, otherwise cancel submit process and show an error message.</p>

<p>On legacy Google forms there were ways to create handlers, but now everything works under <code>HtmlService</code> approach, and I don’t see examples of how to do it.</p>

<p>Here is my code:</p>

<p><code>code.gs</code>:</p>

<pre><code>function doGet()
{
   return HtmlService.createHtmlOutputFromFile('sdi')
  .setSandboxMode(HtmlService.SandboxMode.IFRAME);
}

function doEval()
{
    var frm = FormApp.getActiveForm();
    var items = frm.getItems();
    var text= items[1].asTextItem();
    text.setTitle("I can access the field from here!");
}
</code></pre>

<p><code>sdi.html</code>:</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;script&gt;
  function onSuccess(isOk)
  {
  }

  google.script.run.withSuccessHandler(onSuccess)
      .doEval();
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>