0

I need to be able to disable the OK button in Google Scripts until the User has input text into the prompt. Is there a way to do this?

Have tried to use the following code but it just aborts the process.

var ui = SpreadsheetApp.getUi();
var examinerName = ui.prompt('Random Text.', ui.ButtonSet.OK_CANCEL);

// Process the user's response.



if (examinerName !== "" && ui.Button.OK) {
 ui.alert('Process Aborted'); // Aborts the process and stops the script showing an alert.
 return false;
} else (examinerName === ""  && ui.Button.OK); {
  Logger.log('The user\'s name is %s.', examinerName.getResponseText());
}

I would like it to wait until there is some text and then complete the script

Robert Hall
  • 191
  • 3
  • 11
  • Ok, so i Have it working so that in aborts the process if there is no input. But now if i put some text in the field but press cancel, the script still runs. Any ideas?? – Robert Hall Apr 09 '19 at 10:51
  • `if (ui.Button.CANCEL || examinerName === "") {return;}` – Alan Wells Apr 09 '19 at 18:04
  • 1
    @AlanWells thanks for the code. I had to add it as the following in the end. `if (examinerName.getSelectedButton() == ui.Button.CANCEL || examinerName.getResponseText() === "")` – Robert Hall Apr 10 '19 at 06:53

1 Answers1

0

Set the button as disabled and use the onInput Event https://www.w3schools.com/jsref/event_oninput.asp to enable it.