From 47604c0553c4ffa0e71e92636ba36dbadf53c97b Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Mon, 24 Feb 2020 16:18:00 +0100 Subject: [PATCH] feat(modals): add inputText property to prompt for prefilled text --- .../capacitor/src/main/java/com/getcapacitor/Dialogs.java | 5 ++++- .../src/main/java/com/getcapacitor/plugin/Modals.java | 3 ++- core/src/core-plugin-definitions.ts | 1 + core/src/web/modals.ts | 2 +- electron/src/electron/modals.ts | 2 +- ios/Capacitor/Capacitor/Plugins/Modals.swift | 2 ++ 6 files changed, 11 insertions(+), 4 deletions(-) diff --git a/android/capacitor/src/main/java/com/getcapacitor/Dialogs.java b/android/capacitor/src/main/java/com/getcapacitor/Dialogs.java index 321b2c28b..273f19223 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 828e38efb..414c4d1af 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 330ff53f5..00070343f 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 ff462edcb..c8e1d5ee5 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 1bb211b73..b57c9a428 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 0840a6d66..d61700bee 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