Skip to content

Commit 0526efe

Browse files
ikoevskarigor789
authored andcommitted
Updated documentation for prompt (#119)
* Updated documentation for prompt * Fixed heading style * Update prompt.md
1 parent 8b16a93 commit 0526efe

File tree

1 file changed

+55
-19
lines changed

1 file changed

+55
-19
lines changed
+55-19
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,71 @@
11
---
22
title: PromptDialog
33
apiRef: https://docs.nativescript.org/api-reference/modules/_ui_dialogs_#prompt
4-
contributors: [MisterBrownRSA, rigor789]
4+
contributors: [MisterBrownRSA, rigor789, ikoevska]
55
---
66

7-
The PromptDialog allows you to prompt the user for input.
7+
The `prompt()` method shows a dialog with a single-line field for user input.
88

9-
---
9+
The method is part of the [`dialogs` module](https://docs.nativescript.org/api-reference/modules/_ui_dialogs_).
1010

11-
```javascript
12-
const dialogs = require('tns-core-modules/ui/dialogs')
11+
---
1312

14-
module.exports = {
15-
mounted() {
16-
dialogs.prompt('How are you?', 'Amazing!')
17-
.then(result => {
18-
console.log(`Dialog result: ${result.result}, text: ${result.text}`)
19-
})
20-
}
21-
}
22-
```
13+
## Basic use
2314

24-
The PromptDialog is also available globally, so instead of importing it from the dialogs module, you can simply call
15+
The `prompt()` method is available globally. You can call it anywhere in your app.
2516

26-
```javascript
27-
prompt('How are you?', 'Amazing!')
17+
```JavaScript
18+
prompt('Your message to the user', 'Suggested user input')
2819
.then(result => {
2920
console.log(`Dialog result: ${result.result}, text: ${result.text}`)
3021
})
3122
```
3223

33-
anywhere in your code.
24+
## Configure dialog options
25+
26+
```JavaScript
27+
prompt({
28+
title: "Your dialog title",
29+
message: "Your message",
30+
okButtonText: "Your OK button text",
31+
cancelButtonText: "Your Cancel button text",
32+
defaultText: "Suggested user input",
33+
}).then(result => {
34+
console.log(`Dialog result: ${result.result}, text: ${result.text}`)
35+
});
36+
```
37+
38+
## Configure input type
39+
40+
You can also configure the input type using `inputType`. You can choose between plain text (`text`), email-enabled input (`email`), and password-like hidden input (`password`).
41+
42+
```JavaScript
43+
inputType: dialogs.inputType.text
44+
inputType: dialogs.inputType.email
45+
inputType: dialogs.inputType.password
46+
```
47+
48+
**NOTE:** This option is not globally available and you need to require the `dialogs` module in your app before using `inputType`.
49+
50+
```JavaScript
51+
const dialogs = require('tns-core-modules/ui/dialogs')
52+
```
53+
54+
### Example
55+
56+
```JavaScript
57+
const dialogs = require('tns-core-modules/ui/dialogs')
58+
59+
prompt({
60+
title: "Email Prompt",
61+
message: "Provide your email address:",
62+
okButtonText: "OK",
63+
cancelButtonText: "Cancel",
64+
defaultText: "[email protected]",
65+
inputType: dialogs.inputType.email
66+
}).then(result => {
67+
console.log(`Dialog result: ${result.result}, text: ${result.text}`)
68+
});
69+
```
3470

35-
[> screenshots for=PromptDialog <]
71+
[> screenshots for=PromptDialog <]

0 commit comments

Comments
 (0)