mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
feat: add number and phone input types for prompt dialog (#6365)
This commit is contained in:
committed by
Manol Donev
parent
7fbdc7adc8
commit
7e7c050064
@@ -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 }}" />
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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) {
|
||||
|
||||
16
tns-core-modules/ui/dialogs/dialogs.d.ts
vendored
16
tns-core-modules/ui/dialogs/dialogs.d.ts
vendored
@@ -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>;
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user