Skip to content

Commit 996a475

Browse files
feat: add default value support for text and select inputs
1 parent eadea9d commit 996a475

File tree

3 files changed

+82
-2
lines changed

3 files changed

+82
-2
lines changed

content/scripts/api-reference/input.mdx

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Prompts the user to enter text.
2525

2626
**Parameters:**
2727
- `label` (`string`): The prompt text to display to the user
28+
- `options` (`object`, optional): Additional options for the text input
29+
- `defaultValue` (`string`, optional): Default value for the text input
2830

2931
**Returns:** `Promise<string>` - A promise that resolves to the text entered by the user
3032

@@ -34,9 +36,13 @@ Prompts the user to enter text.
3436
const name = await input.textAsync('What is your name?');
3537
output.text(`Hello, ${name}!`);
3638

37-
// Ask for an email subject
38-
const subject = await input.textAsync('Enter email subject:');
39+
// Ask for an email subject with a default value
40+
const subject = await input.textAsync('Enter email subject:', {defaultValue: 'Monthly Newsletter'});
3941
output.text(`Email subject: ${subject}`);
42+
43+
// Ask for user's name with a default
44+
const userName = await input.textAsync('What is your name?', {defaultValue: 'Anonymous'});
45+
output.text(`Hello, ${userName}!`);
4046
```
4147

4248
**Output:**
@@ -99,6 +105,7 @@ Presents a dropdown menu of options for the user to choose from.
99105
**Parameters:**
100106
- `label` (`string`): The prompt text to display to the user
101107
- `options` (`Array<string | { label: string, value: any }>`): An array of options, either as strings or objects with label and value properties
108+
- `defaultValue` (any, optional): Default selected value
102109

103110
**Returns:** `Promise<any>` - A promise that resolves to the value of the selected option
104111

@@ -110,6 +117,14 @@ const department = await input.selectAsync(
110117
['Marketing', 'Sales', 'Engineering', 'Customer Support', 'Finance', 'HR']
111118
);
112119
output.text(`Selected department: ${department}`);
120+
121+
// Ask user to select a department with a default value
122+
const dept = await input.selectAsync(
123+
'Select a department:',
124+
['Marketing', 'Sales', 'Engineering', 'Customer Support', 'Finance', 'HR'],
125+
'Engineering' // default value
126+
);
127+
output.text(`Selected department: ${dept}`);
113128
```
114129

115130
**Output:**
@@ -127,6 +142,18 @@ const priority = await input.selectAsync(
127142
]
128143
);
129144
output.text(`Selected priority level: ${priority}`);
145+
146+
// Ask user to select a priority level with a default value
147+
const priorityLevel = await input.selectAsync(
148+
'Select priority level:',
149+
[
150+
{ label: 'High (Urgent)', value: 3 },
151+
{ label: 'Medium (Normal)', value: 2 },
152+
{ label: 'Low (When time permits)', value: 1 }
153+
],
154+
2 // default value (Medium)
155+
);
156+
output.text(`Selected priority level: ${priorityLevel}`);
130157
```
131158

132159
**Output:**

content/scripts/changelog.mdx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,26 @@ icon: 'clock'
66

77
This page documents all changes to the NocoDB Scripts API, including new features, improvements, bug fixes, and breaking changes.
88

9+
## October 01, 2025
10+
11+
#### Input Methods Enhancement
12+
- **Default Values for `input.textAsync()`** - Added optional `defaultValue` parameter in options object
13+
- Example: `await input.textAsync('Enter name:', {defaultValue: 'Anonymous'})`
14+
- Pre-fills the input field with a default value that users can accept or modify
15+
- **Default Values for `input.selectAsync()`** - Added optional `defaultValue` parameter
16+
- Example: `await input.selectAsync('Select option:', options, defaultValue)`
17+
- Pre-selects an option in the dropdown menu
18+
19+
#### External Package Imports
20+
- **Dynamic Import Support** - Scripts can now import external JavaScript packages from CDN using dynamic imports
21+
- Use `await import('package-name')` syntax to load external libraries
22+
- Example: `const _ = await import('lodash')` or `const dayjs = await import('dayjs')`
23+
- Supports popular CDNs: esm.sh (default), unpkg, skypack, jsdelivr
24+
- Enables use of popular libraries like lodash, dayjs, axios, etc.
25+
- **Note:** Only dynamic imports are supported; static imports are not available
26+
27+
---
28+
929
## July 28, 2025
1030

1131

content/scripts/index.mdx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ NocoDB Scripts is a powerful automation engine that allows you to write JavaScri
1616
- **Database Access**: Query tables and views, create, update, and delete records
1717
- **User Interaction**: Collect input from users with interactive prompts
1818
- **External Integration**: Connect to third-party services via HTTP requests
19+
- **External Package Imports**: Import and use popular NPM packages from CDN (lodash, dayjs, etc.)
1920
- **Visual Output**: Display results in formatted tables, markdown, and more
2021
- **TypeScript Support**: Enjoy code completion and type checking in the script editor
2122

@@ -103,4 +104,36 @@ if (count > 0) {
103104
- **Output**: Display formatted results with text, markdown, tables, and progress indicators
104105
- **API Integration**: Connect to external services and NocoDB's REST APIs
105106

107+
## Using External Packages
108+
109+
NocoDB Scripts supports importing external JavaScript packages from CDN using **dynamic imports**, allowing you to leverage popular NPM libraries in your scripts.
110+
111+
<Callout type="warning">
112+
**Important:** Only dynamic imports using `import()` are supported. Static imports (e.g., `import _ from 'lodash'`) are not supported.
113+
</Callout>
114+
115+
```javascript
116+
// Use dynamic imports to load external packages
117+
const _ = await import('lodash');
118+
const dayjs = (await import('dayjs')).default;
119+
120+
// Use lodash for data manipulation
121+
const table = base.getTable('Customers');
122+
const records = await table.selectRecordsAsync();
123+
124+
const groupedByStatus = _.groupBy(records.records, record =>
125+
record.getCellValue('Status')
126+
);
127+
128+
output.text(`Customers by status:`);
129+
for (const [status, customers] of Object.entries(groupedByStatus)) {
130+
output.text(`${status}: ${customers.length} customers`);
131+
}
132+
133+
// Use dayjs for date formatting
134+
const today = dayjs().format('MMMM D, YYYY');
135+
output.text(`Report generated on: ${today}`);
136+
137+
```
138+
106139

0 commit comments

Comments
 (0)