Skip to content
Merged
4 changes: 3 additions & 1 deletion apps/app/ui-tests-app/dialogs/dialogs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}" />
Expand Down
40 changes: 40 additions & 0 deletions apps/app/ui-tests-app/dialogs/view-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 10 additions & 0 deletions tns-core-modules/ui/dialogs/dialogs-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

/**
Expand Down
4 changes: 4 additions & 0 deletions tns-core-modules/ui/dialogs/dialogs.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 13 additions & 3 deletions tns-core-modules/ui/dialogs/dialogs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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>;

Expand All @@ -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>;

Expand All @@ -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>;

Expand Down
4 changes: 4 additions & 0 deletions tns-core-modules/ui/dialogs/dialogs.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down