feat: add number and phone input types for prompt dialog (#6365)

This commit is contained in:
Shyam Seshadri
2018-11-07 21:02:20 +05:30
committed by Manol Donev
parent 7fbdc7adc8
commit 7e7c050064
6 changed files with 74 additions and 4 deletions

View File

@@ -7,7 +7,9 @@
<Button text="login" tap="{{ loginName }}" />
<Button text="promptText" tap="{{ promptText }}" />
<Button text="promptPass" tap="{{ promptPass }}" />
<Button text="promptEmail" tap="{{ promptEmail }}" />
<Button text="promptEmail" tap="{{ promptEmail }}" />
<Button text="promptNumber" tap="{{ promptNumber }}" />
<Button text="promptPhone" tap="{{ promptPhone }}" />
<Button text="promptCapitalizationNone" tap="{{ promptCapitalizationNone }}" />
<Button text="promptCapitalizationAll" tap="{{ promptCapitalizationAll }}" />
<Button text="promptCapitalizationSentences" tap="{{ promptCapitalizationSentences }}" />

View File

@@ -138,6 +138,46 @@ export class SettingsViewModel extends observable.Observable {
});
}
public promptNumber(args: observable.EventData) {
dialogs.prompt({
title: "Name",
message: "Enter a number:",
cancelButtonText: "Cancel",
neutralButtonText: "Ignore",
okButtonText: "OK",
defaultText: "1234",
inputType: dialogs.inputType.number
}).then((promptResult) => {
console.log("### Result: " + promptResult.result + ", Text: " + promptResult.text);
if (promptResult.result) {
this.set("name", promptResult.text);
}
else {
this.set("name", "1234");
}
});
}
public promptPhone(args: observable.EventData) {
dialogs.prompt({
title: "Name",
message: "Enter a phone:",
cancelButtonText: "Cancel",
neutralButtonText: "Ignore",
okButtonText: "OK",
defaultText: "1234",
inputType: dialogs.inputType.phone
}).then((promptResult) => {
console.log("### Result: " + promptResult.result + ", Text: " + promptResult.text);
if (promptResult.result) {
this.set("name", promptResult.text);
}
else {
this.set("name", "1234");
}
});
}
public promptCapitalizationNone(args: observable.EventData) {
dialogs.prompt({
title: "Name",

View File

@@ -31,6 +31,16 @@ export module inputType {
* Email input type.
*/
export const email: string = "email";
/**
* Number input type
*/
export const number: string = "number";
/**
* Phone input type
*/
export const phone: string = "phone";
}
/**

View File

@@ -184,6 +184,10 @@ export function prompt(arg: any): Promise<PromptResult> {
input.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD);
} else if (options.inputType === inputType.email) {
input.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
} else if (options.inputType === inputType.number) {
input.setInputType(android.text.InputType.TYPE_CLASS_NUMBER);
} else if (options.inputType === inputType.phone) {
input.setInputType(android.text.InputType.TYPE_CLASS_PHONE);
}
switch (options.capitalizationType) {

View File

@@ -21,6 +21,16 @@ export module inputType {
* Email input type.
*/
export var email: string;
/**
* Number input type.
*/
export var number: string;
/**
* Phone input type.
*/
export var phone: string;
}
/**
@@ -81,7 +91,7 @@ export function prompt(message: string, defaultText?: string): Promise<PromptRes
/**
* The prompt() method displays a dialog box that prompts the visitor for input.
* @param options The options for the dialog box.
* @param options The options for the dialog box.
*/
export function prompt(options: PromptOptions): Promise<PromptResult>;
@@ -95,7 +105,7 @@ export function login(message: string, userName?: string, password?: string): Pr
/**
* The login() method displays a login dialog box that prompts the visitor for user name and password.
* @param options The options for the dialog box.
* @param options The options for the dialog box.
*/
export function login(options: LoginOptions): Promise<LoginResult>;
@@ -109,7 +119,7 @@ export function action(message: string, cancelButtonText: string, actions: Array
/**
* The action() method displays a action box that prompts the visitor to choose some action.
* @param options The options for the dialog box.
* @param options The options for the dialog box.
*/
export function action(options: ActionOptions): Promise<string>;

View File

@@ -104,6 +104,10 @@ export function prompt(arg: any): Promise<PromptResult> {
if (options && options.inputType === inputType.email) {
arg.keyboardType = UIKeyboardType.EmailAddress;
} else if (options && options.inputType === inputType.number) {
arg.keyboardType = UIKeyboardType.NumberPad;
} else if (options && options.inputType === inputType.phone) {
arg.keyboardType = UIKeyboardType.PhonePad;
}
let color = getTextFieldColor();