Class PromptResponse

PromptResponse

Google アプリのユーザー インターフェース環境に表示される prompt ダイアログに対するレスポンス。このレスポンスには、ユーザーがダイアログの入力フィールドに入力したテキストが含まれ、ユーザーがダイアログを閉じるためにクリックしたボタンが示されます。

// Display a dialog box with a title, message, input field, and "Yes" and "No" buttons. The
// user can also close the dialog by clicking the close button in its title bar.
var ui = DocumentApp.getUi();
var response = ui.prompt('Getting to know you', 'May I know your name?', ui.ButtonSet.YES_NO);

// Process the user's response.
if (response.getSelectedButton() == ui.Button.YES) {
  Logger.log('The user\'s name is %s.', response.getResponseText());
} else if (response.getSelectedButton() == ui.Button.NO) {
  Logger.log('The user didn\'t want to provide a name.');
} else {
  Logger.log('The user clicked the close button in the dialog\'s title bar.');
}

Methods

メソッド戻り値の型概要
getResponseText()Stringユーザーがダイアログの入力フィールドに入力したテキストを取得します。
getSelectedButton()Buttonユーザーがダイアログを閉じるためにクリックしたボタンを取得します。

詳細なドキュメント

getResponseText()

ユーザーがダイアログの入力フィールドに入力したテキストを取得します。ユーザーが「キャンセル」やダイアログのタイトルバーの閉じるボタンなど、否定的な表現のボタンをクリックしてダイアログを閉じた場合でも、テキストを使用できます。getSelectedButton() は、ユーザーが意図していたレスポンス テキストが有効かどうかを判断するのに役立ちます。

リターン

String - ユーザーがダイアログの入力フィールドに入力したテキスト。


getSelectedButton()

ユーザーがダイアログを閉じるためにクリックしたボタンを取得します。ユーザーがすべてのダイアログのタイトルバーに含まれている閉じるボタンをクリックすると、このメソッドは Button.CLOSE を返します。

リターン

Button - ユーザーがクリックしたボタン。