我试图在按钮上的谷歌表格侧边栏中显示加载程序,单击完整页面或至少单击按钮,以便提交表单的用户在提交较早的表单之前不应再次按下。我已经通过 js/jquery 添加了加载器。虽然它们工作得很好,但它们太快了,甚至无法向用户展示。我可以添加一些延迟,但我不知道脚本需要多长时间才能完成。因此,最好从应用程序脚本/服务器端运行它。
网页:
<form >
<div class="inputbox">
<label for="name"><strong>Client Business Name</strong></label>
<input type="text" placeholder="Client Business Name" name="name" required>
</div>
<div class="inputbox">
<label for="description"><strong>Client Description</strong></label>
<input type="text" placeholder="Client Description" name="description" required>
</div>
<div class="inputbox">
<label for="domain"><strong>Domain</strong></label>
<input type="url" placeholder="www.example.com" name="domain">
</div>
<div class="inputbox">
<label for="homepage"><strong>Home Page</strong></label>
<input type="url" placeholder="www.example.com/home" name="homepage" >
</div>
<div class="inputbox">
<label for="kpi"><strong>Link Goal Per month</strong></label>
<input type="url" placeholder="www.example.com/home/blog" name="kpi" >
</div>
<button id="btn" onclick="addvalues" >Add</button>
</form>
JS:
<script>
function addvalues() {
document.getElementById("btn").innerHTML = "Adding.."
document.getElementById("btn").setAttribute('disabled', 'disabled')
google.script.run.clientAdd()
}
</script>
应用脚本:
function clientAdd(form) {
var ss = SpreadsheetApp.getActive();
var sheet = ss.getSheetByName('Clients');
sheet.getRange(sheet.getLastRow() + 1, 2).setValue(form.name);
sheet.getRange(sheet.getLastRow(), 3).setValue(form.domain);
sheet.getRange(sheet.getLastRow(), 4).setValue(form.homepage);
sheet.getRange(sheet.getLastRow(), 5).setValue(form.description);
sheet.getRange(sheet.getLastRow(), 6).setValue(form.kpi);
}