Why should the Commenting out of a ui.alert cause the submission of a Modal Dialog to fail to close on submission? The functions still actually do what they are supposed to do, but the Dialog won't go away; you have to click the close button. I've been using Alert Boxes to troubleshoot my work, and now as I Comment them out, I find that there is one that I can't, without producing this problem.
The line in question is the only one commented out here:
function getStartFromDialog (form) {
scriptProperties.getProperties();
var option1 = scriptProperties.getProperty('savedOption1');
var option2 = scriptProperties.getProperty('savedOption2');
var eRow = scriptProperties.getProperty('savedRow');
var tabName = scriptProperties.getProperty('savedTab');
var start = form.chosenStart;
// ui.alert ('Chosen option is ' start);
if (start == 'option1'){var adjustedStart = option1}
else {var adjustedStart = option2}
reactToUserEntryOfStart (adjustedStart,eRow);
}
Here is the index.htm file:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
<script>
function submitForm() {
google.script.run.getStartFromDialog(document.getElementById("startChoiceForm"));
document.getElementById("form").style.display = "none";
}
</script>
</head>
<body>
<div>
<div id="form">
<? var offeredStart1 = offeredStarts[0]; var offeredStart2 = offeredStarts[1] ?>
<form id="startChoiceForm">
<select name="chosenStart" id ="chosenStart">
<option value="option1"><?= offeredStart1 ?></option>
<option value="option2"><?= offeredStart2 ?></option>
</select>
<div>
<input type="submit" value="Submit" onclick="submitForm()" >
<input type="button" value="Close" onclick="google.script.host.close()" >
</div>
</form>
</div>
</body>
</html>
This video demonstrates:
- Functions working;
- My Commenting out that line ui.alert ('Chosen option is ' start);
- Same procedure; now Dialog Box hangs.
The scripts allow the user to enter times in testUserEntTime!A3:A without typing a colon or specifying AM/PM, ie 325 for either 3:25am or 3:25pm. It automatically turns these entries into date-time values so that they are always sequential top-to-bottom, permitting no date-time to be earlier than the one before.
The dialog box is triggered by the entering of a time which has the same hour as the time above it, but earlier minutes. In the video, the previous time is 4:55 am 9/5/2001 (formatted so only the time shows) and I am entering 450. This causes the script to ask whether I intend to indicate 4:50pm, or 4:50am on the next day, 9/6.
Thank you for your help; I'm bewildered.
YouTube video demonstrating bug
CodePudding user response:
When I saw your sample Spreadsheet and your current script, in your situation, how about the following modification?
From:
google.script.run.getStartFromDialog(document.getElementById("startChoiceForm"));
To:
google.script.run.withSuccessHandler(google.script.host.close).getStartFromDialog(document.getElementById("startChoiceForm"));
- When
ui.alert ('Chosen option is ' start);
is used in the functiongetStartFromDialog
, the dialog is overwritten byui.alert
. By this, when the ok button is clicked, the dialog is closed. When you want to close the dialog by clicking submit button,google.script.host.close
is run usingwithSuccessHandler
.