在 URL Google 应用程序脚本和更新字段上传递参数
Pass parameters on URL Google apps Script and updates fields
我有一个带有应用程序脚本的 HTML 表单和 Bootstrap 4。在该表单中,我有一个输入字段,它的值来自 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”没有更新。
我的问题是什么?
我相信你的目标如下。
- 您想通过访问 URL 来修改
estado
的文本框,包括 https://script.google.com/macros/s/###/exec?inputid=###
. 等查询参数
修改点:
- 这样的话,修改
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时,通过执行getId()
.[=34的函数修改estado
文本框的值=]
参考:
我有一个带有应用程序脚本的 HTML 表单和 Bootstrap 4。在该表单中,我有一个输入字段,它的值来自 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”没有更新。
我的问题是什么?
我相信你的目标如下。
- 您想通过访问 URL 来修改
estado
的文本框,包括https://script.google.com/macros/s/###/exec?inputid=###
. 等查询参数
修改点:
- 这样的话,修改
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时,通过执行getId()
.[=34的函数修改estado
文本框的值=]