Skip to content

Commit 408614d

Browse files
acrolletmanoldonev
authored andcommitted
feat(dialog): add decimal input type for prompt dialog (#6805)
1 parent 672c821 commit 408614d

File tree

12 files changed

+84
-22
lines changed

12 files changed

+84
-22
lines changed

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

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Button.even, Button.odd {
2+
border-radius: 5;
3+
color: white;
4+
margin: 0 5 5 0;
5+
}
6+
7+
Button.even {
8+
background-color: #0000cc;
9+
}
10+
11+
Button.odd {
12+
background-color: #33cc33;
13+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@import './main-page-common.css';
2+
3+
Button.even, Button.odd {
4+
height: 25;
5+
font-size: 10;
6+
padding: 0;
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@import './main-page-common.css';
2+
3+
Button.even, Button.odd {
4+
padding: 5;
5+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Page loaded="pageLoaded">
2+
<GridLayout rows="auto, *">
3+
<Label text="{{ name }}" id="label" style="text-align:center;" />
4+
<WrapLayout row="1">
5+
<Button class="even" text="action" tap="{{ actionName }}" />
6+
<Button class="odd" text="alert" tap="{{ alertName }}" />
7+
<Button class="even" text="confirm" tap="{{ confirmName }}" />
8+
<Button class="odd" text="login" tap="{{ loginName }}" />
9+
<Button class="even" text="promptText" tap="{{ promptText }}" />
10+
<Button class="odd" text="promptPass" tap="{{ promptPass }}" />
11+
<Button class="even" text="promptEmail" tap="{{ promptEmail }}" />
12+
<Button class="odd" text="promptNumber" tap="{{ promptNumber }}" />
13+
<Button class="even" text="promptDecimal" tap="{{ promptDecimal }}" />
14+
<Button class="odd" text="promptPhone" tap="{{ promptPhone }}" />
15+
<Button class="even" text="promptCapitalizationNone" tap="{{ promptCapitalizationNone }}" />
16+
<Button class="odd" text="promptCapitalizationAll" tap="{{ promptCapitalizationAll }}" />
17+
<Button class="even" text="promptCapitalizationSentences" tap="{{ promptCapitalizationSentences }}" />
18+
<Button class="odd" text="promptCapitalizationWords" tap="{{ promptCapitalizationWords }}" />
19+
</WrapLayout>
20+
</GridLayout>
21+
</Page>

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ export class SettingsViewModel extends observable.Observable {
121121
public promptEmail(args: observable.EventData) {
122122
dialogs.prompt({
123123
title: "Name",
124-
message: "Enter name:",
124+
message: "Enter email:",
125125
cancelButtonText: "Cancel",
126126
neutralButtonText: "Ignore",
127127
okButtonText: "OK",
128-
defaultText: "John Reese",
128+
defaultText: "john.reese@nativescript.org",
129129
inputType: dialogs.inputType.email
130130
}).then((promptResult) => {
131131
console.log("### Result: " + promptResult.result + ", Text: " + promptResult.text);
@@ -158,6 +158,26 @@ export class SettingsViewModel extends observable.Observable {
158158
});
159159
}
160160

161+
public promptDecimal(args: observable.EventData) {
162+
dialogs.prompt({
163+
title: "Name",
164+
message: "Enter a decimal number:",
165+
cancelButtonText: "Cancel",
166+
neutralButtonText: "Ignore",
167+
okButtonText: "OK",
168+
defaultText: "13.50",
169+
inputType: dialogs.inputType.decimal
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", "13.50");
177+
}
178+
});
179+
}
180+
161181
public promptPhone(args: observable.EventData) {
162182
dialogs.prompt({
163183
title: "Name",

apps/app/ui-tests-app/main-page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function pageLoaded(args: EventData) {
1212
examples.set("bindings", "bindings/main-page");
1313
examples.set("button", "button/main-page");
1414
examples.set("css", "css/main-page");
15-
examples.set("dialogs", "dialogs/dialogs");
15+
examples.set("dialogs", "dialogs/main-page");
1616
examples.set("events", "events/main-page");
1717
examples.set("fonts", "font/main-page");
1818
examples.set("flexbox", "flexbox/flexbox-main-page");

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ export module inputType {
3939
*/
4040
export const number: string = "number";
4141

42+
/**
43+
* Decimal input type
44+
*/
45+
export const decimal: string = "decimal";
46+
4247
/**
4348
* Phone input type
4449
*/

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ export function prompt(arg: any): Promise<PromptResult> {
185185
} else if (options.inputType === inputType.email) {
186186
input.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
187187
} else if (options.inputType === inputType.number) {
188-
input.setInputType(android.text.InputType.TYPE_CLASS_NUMBER);
188+
input.setInputType(android.text.InputType.TYPE_CLASS_NUMBER);
189+
} else if (options.inputType === inputType.decimal) {
190+
input.setInputType(android.text.InputType.TYPE_CLASS_NUMBER | android.text.InputType.TYPE_NUMBER_FLAG_DECIMAL);
189191
} else if (options.inputType === inputType.phone) {
190192
input.setInputType(android.text.InputType.TYPE_CLASS_PHONE);
191193
}

0 commit comments

Comments
 (0)