在上一个关于在GS和html之间传递值的问题后,我取得了一些进展。我能够将html侧边栏中的文本输入值存储到Google propertiesservice中,然后再次打开它时将其传递回边栏。然而,这对我的单选按钮似乎不起作用。有谁可以帮我解决这个问题?
以下代码处理侧栏的输入
function processForm(form) {
radio = form.radioEmail;
userProperties.setProperty('selectedRadio', radio);
time = form.time;
userProperties.setProperty('selectedTime', time);
};
以下代码将存储的inpout放入html侧边栏:
function openTasksSettings() {
var htmlTemplate = HtmlService.createTemplateFromFile('tasksSettings');
htmlTemplate.timehtml = time;
htmlTemplate.radiohtml = radio;
var html = htmlTemplate.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setTitle('Settings')
.setWidth(300)
SpreadsheetApp.getUi()
.showSidebar(html);
return html
};
最后是html代码(减去非相关部分)
<div>
<form>
<strong>Send email reminders:</strong><br>
<input type="radio" name="radioEmail" id="radio1" value="<?!= radiohtml ?>" Yes>
<label for="radio1">Yes</label>
<input type="radio" name="radioEmail" id="radio2" value="<?!= radiohtml ?>" No>
<label for="radio2">No</label><br><br>
<strong>Send reminders:</strong><br>
<input type="text" name="time" id="time" style="width: 40px;" value="<?!= timehtml ?>">
<label for="select">days before due date</label>
<br><br><input type="button" class="action" onClick="writeFormData(); alert('submitted')" value="Submit"/>
</form>
</div>
<script type="text/javascript">
function writeFormData() {
google.script.run.processForm(document.forms[0]);
}
</script>
虽然它似乎不会影响存储和传递时间值,但在调试GS代码时会出现以下错误:
TypeError:无法读取属性&#34; radioEmail&#34;来自undefined
任何帮助将不胜感激!