diff --git a/android/capacitor/src/main/java/com/getcapacitor/Dialogs.java b/android/capacitor/src/main/java/com/getcapacitor/Dialogs.java index 321b2c28bf..273f192239 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/Dialogs.java +++ b/android/capacitor/src/main/java/com/getcapacitor/Dialogs.java @@ -137,7 +137,7 @@ public static void prompt(final Context context, final String message, final Dialogs.OnResultListener listener) { - prompt(context, message, null, null, null, null, listener); + prompt(context, message, null, null, null, null, null, listener); } public static void prompt(final Context context, @@ -146,11 +146,13 @@ public static void prompt(final Context context, final String okButtonTitle, final String cancelButtonTitle, final String inputPlaceholder, + final String inputText, final Dialogs.OnResultListener listener) { final String promptTitle = title == null ? "Prompt" : title; final String promptOkButtonTitle = okButtonTitle == null ? "OK" : okButtonTitle; final String promptCancelButtonTitle = cancelButtonTitle == null ? "Cancel" : cancelButtonTitle; final String promptInputPlaceholder = inputPlaceholder == null ? "" : inputPlaceholder; + final String promptInputText = inputText == null ? "" : inputText; new Handler(Looper.getMainLooper()).post(new Runnable() { @Override @@ -159,6 +161,7 @@ public void run() { final EditText input = new EditText(context); input.setHint(promptInputPlaceholder); + input.setText(promptInputText); builder .setMessage(message) diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/Modals.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/Modals.java index 828e38efb5..414c4d1af8 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/Modals.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/Modals.java @@ -78,6 +78,7 @@ public void prompt(final PluginCall call) { final String okButtonTitle = call.getString("okButtonTitle", "OK"); final String cancelButtonTitle = call.getString("cancelButtonTitle", "Cancel"); final String inputPlaceholder = call.getString("inputPlaceholder", ""); + final String inputText = call.getString("inputText", ""); if(title == null || message == null) { call.error("Please provide a title or message for the alert"); @@ -89,7 +90,7 @@ public void prompt(final PluginCall call) { return; } - Dialogs.prompt(c, message, title, okButtonTitle, cancelButtonTitle, inputPlaceholder, new Dialogs.OnResultListener() { + Dialogs.prompt(c, message, title, okButtonTitle, cancelButtonTitle, inputPlaceholder, inputText, new Dialogs.OnResultListener() { @Override public void onResult(boolean value, boolean didCancel, String inputValue) { JSObject ret = new JSObject(); diff --git a/core/src/core-plugin-definitions.ts b/core/src/core-plugin-definitions.ts index 330ff53f50..00070343fd 100644 --- a/core/src/core-plugin-definitions.ts +++ b/core/src/core-plugin-definitions.ts @@ -1115,6 +1115,7 @@ export interface PromptOptions { okButtonTitle?: string; cancelButtonTitle?: string; inputPlaceholder?: string; + inputText?: string; } export interface ConfirmOptions { diff --git a/core/src/web/modals.ts b/core/src/web/modals.ts index ff462edcb1..c8e1d5ee5c 100644 --- a/core/src/web/modals.ts +++ b/core/src/web/modals.ts @@ -25,7 +25,7 @@ export class ModalsPluginWeb extends WebPlugin implements ModalsPlugin { } async prompt(options: PromptOptions): Promise { - const val = window.prompt(options.message, options.inputPlaceholder || ''); + const val = window.prompt(options.message, options.inputText || ''); return Promise.resolve({ value: val, cancelled: val === null diff --git a/electron/src/electron/modals.ts b/electron/src/electron/modals.ts index 1bb211b73e..b57c9a428a 100644 --- a/electron/src/electron/modals.ts +++ b/electron/src/electron/modals.ts @@ -33,7 +33,7 @@ export class ModalsPluginElectron extends WebPlugin implements ModalsPlugin { } async prompt(options: PromptOptions): Promise { - const val = window.prompt(options.message, options.inputPlaceholder || ''); + const val = window.prompt(options.message, options.inputText || ''); return Promise.resolve({ value: val, cancelled: val === null diff --git a/ios/Capacitor/Capacitor/Plugins/Modals.swift b/ios/Capacitor/Capacitor/Plugins/Modals.swift index 0840a6d666..d61700bee1 100644 --- a/ios/Capacitor/Capacitor/Plugins/Modals.swift +++ b/ios/Capacitor/Capacitor/Plugins/Modals.swift @@ -58,6 +58,7 @@ public class CAPModalsPlugin : CAPPlugin { let okButtonTitle = call.options["okButtonTitle"] as? String ?? "OK" let cancelButtonTitle = call.options["cancelButtonTitle"] as? String ?? "Cancel" let inputPlaceholder = call.options["inputPlaceholder"] as? String ?? "" + let inputText = call.options["inputText"] as? String ?? "" let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertController.Style.alert) @@ -65,6 +66,7 @@ public class CAPModalsPlugin : CAPPlugin { alert.addTextField { (textField) in textField.placeholder = inputPlaceholder + textField.text = inputText } alert.addAction(UIAlertAction(title: okButtonTitle, style: UIAlertAction.Style.default, handler: { (action) -> Void in