Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(modals): add inputText property to prompt for prefilled text #2475

Merged
merged 1 commit into from
Feb 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -159,6 +161,7 @@ public void run() {
final EditText input = new EditText(context);

input.setHint(promptInputPlaceholder);
input.setText(promptInputText);

builder
.setMessage(message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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();
Expand Down
1 change: 1 addition & 0 deletions core/src/core-plugin-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,7 @@ export interface PromptOptions {
okButtonTitle?: string;
cancelButtonTitle?: string;
inputPlaceholder?: string;
inputText?: string;
}

export interface ConfirmOptions {
Expand Down
2 changes: 1 addition & 1 deletion core/src/web/modals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class ModalsPluginWeb extends WebPlugin implements ModalsPlugin {
}

async prompt(options: PromptOptions): Promise<PromptResult> {
const val = window.prompt(options.message, options.inputPlaceholder || '');
const val = window.prompt(options.message, options.inputText || '');
return Promise.resolve({
value: val,
cancelled: val === null
Expand Down
2 changes: 1 addition & 1 deletion electron/src/electron/modals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class ModalsPluginElectron extends WebPlugin implements ModalsPlugin {
}

async prompt(options: PromptOptions): Promise<PromptResult> {
const val = window.prompt(options.message, options.inputPlaceholder || '');
const val = window.prompt(options.message, options.inputText || '');
return Promise.resolve({
value: val,
cancelled: val === null
Expand Down
2 changes: 2 additions & 0 deletions ios/Capacitor/Capacitor/Plugins/Modals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ 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)

DispatchQueue.main.async {

alert.addTextField { (textField) in
textField.placeholder = inputPlaceholder
textField.text = inputText
}

alert.addAction(UIAlertAction(title: okButtonTitle, style: UIAlertAction.Style.default, handler: { (action) -> Void in
Expand Down