Button does not send form and/or run javascript

Asked

Viewed 94 times

-1

Come on, guys. So... I’m having trouble making the button that would send a completed form to a spreadsheet in Google Sheets and then reset the fields, the entire application is running on the site itself. I am using the javascript below screen call, button action and insert the form data into the spreadsheet, respectively:

function Formulario() {
  // Declaração de vars
  var Form = HtmlService.createTemplateFromFile("formulario");
  var MostrarForm = Form.evaluate();

  // Cria e exibe o formulário de Cad. Processo (280x450)
  MostrarForm.setTitle("Cadastro de Processo").setHeight(280).setWidth(450);
  SpreadsheetApp.getUi().showModalDialog(MostrarForm, "Cadastro de Processo");
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
      <script>
        var CampoProcesso = document.getElementByID("nprocesso");
        var CampoInteressado = document.getElementByID("interessado");
        
        function Salvar(){
          var processo = CampoProcesso.value;
          var interessado = CampoInteressado.value;
          
          google.script.run.RegistrarProcesso(processo, interessado);
        
          CampoProcesso.value = "";
          CampoInteressado.value = "";
          
          M.toast({html: 'Cadastro realizado com sucesso!'});
        }
      </script>

function RegistrarProcesso(processo,interessado) {
  // Declaração de vars
  var Home = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("INÍCIO");
  var Plan = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("LOL");
  
  // Procura a linha para inserir os dados
  Plan.getRange('A1').activate();
  Plan.getCurrentCell().getNextDataCell(SpreadsheetApp.Direction.DOWN).activate();
  Plan.getActiveCell().offset(1, 0).activate();
  
  // Insere os dados na linha
  var Linha = Plan.getCurrentCell().getRow();
  Plan.getRange(Linha, 1).setValue(processo);
  Plan.getRange(Linha, 2).setValue(interessado);
  
  Home.getRange('A1').activate();
}

And the form itself:

<!--Criação do formulário-->
      <div class="container">
        <div class="row">
          <div class="input-field col s12">
            <i class="material-icons prefix">account_circle</i>
            <input id="nprocesso" type="text" autocomplete="off">
            <label for="nprocesso">Nº do Processo</label>
          </div>
          <div class="input-field col s12">
            <i class="material-icons prefix">phone</i>
            <input id="interessado" type="text" autocomplete="off">
            <label for="interessado">Interessado</label>
          </div>
          <div class="input-field col s12">
            <button type="button" onclick="Salvar()" class="btn waves-effect waves-light">Salvar
              <i class="material-icons right">send</i>
            </button>
          </div>
        </div>
      </div>

1 answer

1

From what I saw you didn’t perform any function you created.

You gave a name to the function, so it will only perform if it is called, for example:

Formulario(); RegistrarProcesso();

You also put the save function on onclick of button, but you defined her?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.