【发布时间】: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”不会更新。
我的问题是什么?
【问题讨论】:
-
请阅读developers.google.com/apps-script/guides/web,然后添加minimal reproducible example(添加服务器端(.gs)和客户端(.html)代码)
标签: javascript url google-apps-script google-sheets web-applications