Skip to content

Commit 7e7c050

Browse files
shyamseshadrimanoldonev
authored andcommitted
feat: add number and phone input types for prompt dialog (#6365)
1 parent 7fbdc7a commit 7e7c050

6 files changed

Lines changed: 74 additions & 4 deletions

File tree

‎apps/app/ui-tests-app/dialogs/dialogs.xml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
<Button text="login" tap="{{ loginName }}" />
88
<Button text="promptText" tap="{{ promptText }}" />
99
<Button text="promptPass" tap="{{ promptPass }}" />
10-
<Button text="promptEmail" tap="{{ promptEmail }}" />
10+
<Button text="promptEmail" tap="{{ promptEmail }}" />
11+
<Button text="promptNumber" tap="{{ promptNumber }}" />
12+
<Button text="promptPhone" tap="{{ promptPhone }}" />
1113
<Button text="promptCapitalizationNone" tap="{{ promptCapitalizationNone }}" />
1214
<Button text="promptCapitalizationAll" tap="{{ promptCapitalizationAll }}" />
1315
<Button text="promptCapitalizationSentences" tap="{{ promptCapitalizationSentences }}" />

‎apps/app/ui-tests-app/dialogs/view-model.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,46 @@ export class SettingsViewModel extends observable.Observable {
138138
});
139139
}
140140

141+
public promptNumber(args: observable.EventData) {
142+
dialogs.prompt({
143+
title: "Name",
144+
message: "Enter a number:",
145+
cancelButtonText: "Cancel",
146+
neutralButtonText: "Ignore",
147+
okButtonText: "OK",
148+
defaultText: "1234",
149+
inputType: dialogs.inputType.number
150+
}).then((promptResult) => {
151+
console.log("### Result: " + promptResult.result + ", Text: " + promptResult.text);
152+
if (promptResult.result) {
153+
this.set("name", promptResult.text);
154+
}
155+
else {
156+
this.set("name", "1234");
157+
}
158+
});
159+
}
160+
161+
public promptPhone(args: observable.EventData) {
162+
dialogs.prompt({
163+
title: "Name",
164+
message: "Enter a phone:",
165+
cancelButtonText: "Cancel",
166+
neutralButtonText: "Ignore",
167+
okButtonText: "OK",
168+
defaultText: "1234",
169+
inputType: dialogs.inputType.phone
170+
}).then((promptResult) => {
171+
console.log("### Result: " + promptResult.result + ", Text: " + promptResult.text);
172+
if (promptResult.result) {
173+
this.set("name", promptResult.text);
174+
}
175+
else {
176+
this.set("name", "1234");
177+
}
178+
});
179+
}
180+
141181
public promptCapitalizationNone(args: observable.EventData) {
142182
dialogs.prompt({
143183
title: "Name",

‎tns-core-modules/ui/dialogs/dialogs-common.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ export module inputType {
3131
* Email input type.
3232
*/
3333
export const email: string = "email";
34+
35+
/**
36+
* Number input type
37+
*/
38+
export const number: string = "number";
39+
40+
/**
41+
* Phone input type
42+
*/
43+
export const phone: string = "phone";
3444
}
3545

3646
/**

‎tns-core-modules/ui/dialogs/dialogs.android.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ export function prompt(arg: any): Promise<PromptResult> {
184184
input.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD);
185185
} else if (options.inputType === inputType.email) {
186186
input.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
187+
} else if (options.inputType === inputType.number) {
188+
input.setInputType(android.text.InputType.TYPE_CLASS_NUMBER);
189+
} else if (options.inputType === inputType.phone) {
190+
input.setInputType(android.text.InputType.TYPE_CLASS_PHONE);
187191
}
188192

189193
switch (options.capitalizationType) {

‎tns-core-modules/ui/dialogs/dialogs.d.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ export module inputType {
2121
* Email input type.
2222
*/
2323
export var email: string;
24+
25+
/**
26+
* Number input type.
27+
*/
28+
export var number: string;
29+
30+
/**
31+
* Phone input type.
32+
*/
33+
export var phone: string;
2434
}
2535

2636
/**
@@ -81,7 +91,7 @@ export function prompt(message: string, defaultText?: string): Promise<PromptRes
8191

8292
/**
8393
* The prompt() method displays a dialog box that prompts the visitor for input.
84-
* @param options The options for the dialog box.
94+
* @param options The options for the dialog box.
8595
*/
8696
export function prompt(options: PromptOptions): Promise<PromptResult>;
8797

@@ -95,7 +105,7 @@ export function login(message: string, userName?: string, password?: string): Pr
95105

96106
/**
97107
* The login() method displays a login dialog box that prompts the visitor for user name and password.
98-
* @param options The options for the dialog box.
108+
* @param options The options for the dialog box.
99109
*/
100110
export function login(options: LoginOptions): Promise<LoginResult>;
101111

@@ -109,7 +119,7 @@ export function action(message: string, cancelButtonText: string, actions: Array
109119

110120
/**
111121
* The action() method displays a action box that prompts the visitor to choose some action.
112-
* @param options The options for the dialog box.
122+
* @param options The options for the dialog box.
113123
*/
114124
export function action(options: ActionOptions): Promise<string>;
115125

‎tns-core-modules/ui/dialogs/dialogs.ios.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ export function prompt(arg: any): Promise<PromptResult> {
104104

105105
if (options && options.inputType === inputType.email) {
106106
arg.keyboardType = UIKeyboardType.EmailAddress;
107+
} else if (options && options.inputType === inputType.number) {
108+
arg.keyboardType = UIKeyboardType.NumberPad;
109+
} else if (options && options.inputType === inputType.phone) {
110+
arg.keyboardType = UIKeyboardType.PhonePad;
107111
}
108112

109113
let color = getTextFieldColor();

0 commit comments

Comments
 (0)