【问题标题】:Pass parameters on URL Google apps Script and updates fields在 URL 上传递参数 Google 应用脚本和更新字段
【发布时间】:2020-08-06 02:20:41
【问题描述】:

我有一个带有应用程序脚本和 Bootstrap 4 的 HTML 表单。在该表单中,我有一个输入字段,它的值来自 URL 上的参数。当我将参数传递给字段时,我必须更新第二个字段。但是当我发送带有参数的 url 时,第二个字段不会更新。

这是我的代码:

<div class="form-row">
<div class="form-group col-md-6">
<label for="inputid">Identificador de viaje</label>
<input type="text" class="form-control" id="inputid" required>
  <div class="invalid-feedback">
    No ha ingresado los datos o el viaje señalado ya se encuentra cerrado.
  </div>
  </div>
  <div class="form-group col-md-6">
  <label for="estado">Estado</label>
  <input type="text" class="form-control" id="estado" required disabled>
  <div class="invalid-feedback">
    No ha ingresado los datos o estos no son válidos.
  </div>
  </div> 
  </div>
  <script>
  var arrayOfValues;

  function afterButtonClicked(){

  if(validate()){

  var cuenta = document.getElementById("cuenta");   
  var inputid = document.getElementById("inputid");
  var estado = document.getElementById("estado");
  var kmfinal = document.getElementById("kmfinal");
        
  var rowDataarrive = {cuenta: cuenta.value,inputid:inputid.value,
               estado: estado.value,kmfinal:kmfinal.value,                              
               };
               
  google.script.run.addNewRowarrive(rowDataarrive);
  $('#modal').modal('hide')
  $('#successnotification').toast('show')
  setTimeout(function(){location.reload()}, 6000);
  } else{
  $('#modal').modal('hide')
  $('#errornotification').toast('show')
  }
  }

  function validate(){
   var fieldsToValidate = document.querySelectorAll("#userform input, #userform select");
   Array.prototype.forEach.call(fieldsToValidate, function(el){
  if(el.checkValidity()){
  el.classList.remove("is-invalid");

  }else{
  el.classList.add("is-invalid");

  }
   
   });

   return Array.prototype.every.call(fieldsToValidate, function(el){
   return el.checkValidity();

   });


   }
   function getId(){

   var idCode = document.getElementById("inputid").value;

    google.script.run.withSuccessHandler(updateIdcode).getId(idCode);

    }

    function updateIdcode(estadolist){
    document.getElementById("estado").value = estadolist;

     }
 
     google.script.url.getLocation(function(location) {
     document.getElementById("inputid").value = location.parameters.inputid[0];
     });
     
    document.getElementById("inputid").addEventListener("input",getId);
    document.getElementById("enviar").addEventListener("click",afterButtonClicked);
    document.getElementById("loading").remove();
    </script>

然后,当我在导航器上发送带有参数的 url 时,输入字段“estado”不会更新。

我的问题是什么?

【问题讨论】:

标签: javascript url google-apps-script google-sheets web-applications


【解决方案1】:

我相信你的目标如下。

  • 您想通过访问包含https://script.google.com/macros/s/###/exec?inputid=###等查询参数的URL来修改estado的文本框。

修改点:

  • 这种情况下,修改google.script.url.getLocation怎么样?

修改脚本:

google.script.url.getLocation(function(location) {
  document.getElementById("inputid").value = location.parameters.inputid[0];
  getId();  // Added
});
  • 这样,当你使用https://script.google.com/macros/s/###/exec?inputid=###访问Web Apps时,estado的文本框的值通过执行getId()的函数来修改。

参考:

【讨论】:

  • 我成功地将参数传递给 inputid 但第二个字段 (estado) 没有更新。输入字段 estado 由 inputid 上的值确定。当我更改 inputid 的值时,我的脚本转到数据库并获取 estado 的值,就像来自 excel 的 vlookup 一样。然后,当我更改 inputid 时,我的代码搜索或查找数据库列 estado 上的值。当我在 URL 中传递参数时,字段 estado 不会更新...抱歉,如果我的语法不太好
  • 我在 Code.GS 上更改了一个值,现在可以正常工作了!!但在您的帮助和支持下...非常感谢 Tanaike!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-12
  • 2011-11-14
相关资源
最近更新 更多