File size: 21,894 Bytes
0a84888 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 |
---
#https://www.notion.so/n8n/Frontmatter-432c2b8dff1f43d4b1c8d20075510fe4
contentType: reference
---
# Node user interface elements
n8n provides a set of predefined UI components (based on a JSON file) that allows users to input all sorts of data types. The following UI elements are available in n8n.
## String
Basic configuration:
```typescript
{
displayName: Name, // The value the user sees in the UI
name: name, // The name used to reference the element UI within the code
type: string,
required: true, // Whether the field is required or not
default: 'n8n',
description: 'The name of the user',
displayOptions: { // the resources and operations to display this element with
show: {
resource: [
// comma-separated list of resource names
],
operation: [
// comma-separated list of operation names
]
}
},
}
```

String field for inputting passwords:
```typescript
{
displayName: 'Password',
name: 'password',
type: 'string',
required: true,
typeOptions: {
password: true,
},
default: '',
description: `User's password`,
displayOptions: { // the resources and operations to display this element with
show: {
resource: [
// comma-separated list of resource names
],
operation: [
// comma-separated list of operation names
]
}
},
}
```

String field with more than one row:
```typescript
{
displayName: 'Description',
name: 'description',
type: 'string',
required: true,
typeOptions: {
rows: 4,
},
default: '',
description: 'Description',
displayOptions: { // the resources and operations to display this element with
show: {
resource: [
// comma-separated list of resource names
],
operation: [
// comma-separated list of operation names
]
}
},
}
```

### Support drag and drop for data keys
Users can drag and drop data values to map them to fields. Dragging and dropping creates an [expression](/glossary.md#expression-n8n) to load the data value. n8n supports this automatically.
You need to add an extra configuration option to support dragging and dropping data keys:
* `requiresDataPath: 'single'`: for fields that require a single string.
* `requiresDataPath: 'multiple'`: for fields that can accept a comma-separated list of string.
The [Compare Datasets node code](https://github.com/n8n-io/n8n/blob/master/packages/nodes-base/nodes/CompareDatasets/CompareDatasets.node.ts){:target=_blank .external-link} has examples.
## Number
Number field with decimal points:
```typescript
{
displayName: 'Amount',
name: 'amount',
type: 'number',
required: true,
typeOptions: {
maxValue: 10,
minValue: 0,
numberPrecision: 2,
},
default: 10.00,
description: 'Your current amount',
displayOptions: { // the resources and operations to display this element with
show: {
resource: [
// comma-separated list of resource names
],
operation: [
// comma-separated list of operation names
]
}
},
}
```

## Collection
Use the `collection` type when you need to display optional fields.
```typescript
{
displayName: 'Filters',
name: 'filters',
type: 'collection',
placeholder: 'Add Field',
default: {},
options: [
{
displayName: 'Type',
name: 'type',
type: 'options',
options: [
{
name: 'Automated',
value: 'automated',
},
{
name: 'Past',
value: 'past',
},
{
name: 'Upcoming',
value: 'upcoming',
},
],
default: '',
},
],
displayOptions: { // the resources and operations to display this element with
show: {
resource: [
// comma-separated list of resource names
],
operation: [
// comma-separated list of operation names
]
}
},
}
```

## DateTime
The `dateTime` type provides a date picker.
```typescript
{
displayName: 'Modified Since',
name: 'modified_since',
type: 'dateTime',
default: '',
description: 'The date and time when the file was last modified',
displayOptions: { // the resources and operations to display this element with
show: {
resource: [
// comma-separated list of resource names
],
operation: [
// comma-separated list of operation names
]
}
},
}
```

## Boolean
The `boolean` type adds a toggle for entering true or false.
```typescript
{
displayName: 'Wait for Image',
name: 'waitForImage',
type: 'boolean',
default: true, // Initial state of the toggle
description: 'Whether to wait for the image or not',
displayOptions: { // the resources and operations to display this element with
show: {
resource: [
// comma-separated list of resource names
],
operation: [
// comma-separated list of operation names
]
}
},
}
```

## Color
The `color` type provides a color selector.
```typescript
{
displayName: 'Background Color',
name: 'backgroundColor',
type: 'color',
default: '', // Initially selected color
displayOptions: { // the resources and operations to display this element with
show: {
resource: [
// comma-separated list of resource names
],
operation: [
// comma-separated list of operation names
]
}
},
}
```

## Options
The `options` type adds an options list. Users can select a single value.
```typescript
{
displayName: 'Resource',
name: 'resource',
type: 'options',
options: [
{
name: 'Image',
value: 'image',
},
{
name: 'Template',
value: 'template',
},
],
default: 'image', // The initially selected option
description: 'Resource to consume',
displayOptions: { // the resources and operations to display this element with
show: {
resource: [
// comma-separated list of resource names
],
operation: [
// comma-separated list of operation names
]
}
},
}
```

## Multi-options
The `multiOptions` type adds an options list. Users can select more than one value.
```typescript
{
displayName: 'Events',
name: 'events',
type: 'multiOptions',
options: [
{
name: 'Plan Created',
value: 'planCreated',
},
{
name: 'Plan Deleted',
value: 'planDeleted',
},
],
default: [], // Initially selected options
description: 'The events to be monitored',
displayOptions: { // the resources and operations to display this element with
show: {
resource: [
// comma-separated list of resource names
],
operation: [
// comma-separated list of operation names
]
}
},
}
```

## Filter
Use this component to evaluate, match, or filter incoming data.
This is the code from n8n's own If node. It shows a filter component working with a [collection](#collection) component where users can configure the filter's behavior.
```typescript
{
displayName: 'Conditions',
name: 'conditions',
placeholder: 'Add Condition',
type: 'filter',
default: {},
typeOptions: {
filter: {
// Use the user options (below) to determine filter behavior
caseSensitive: '={{!$parameter.options.ignoreCase}}',
typeValidation: '={{$parameter.options.looseTypeValidation ? "loose" : "strict"}}',
},
},
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add option',
default: {},
options: [
{
displayName: 'Ignore Case',
description: 'Whether to ignore letter case when evaluating conditions',
name: 'ignoreCase',
type: 'boolean',
default: true,
},
{
displayName: 'Less Strict Type Validation',
description: 'Whether to try casting value types based on the selected operator',
name: 'looseTypeValidation',
type: 'boolean',
default: true,
},
],
},
```

## Assignment collection (drag and drop)
Use the drag and drop component when you want users to pre-fill name and value parameters with a single drag interaction.
```typescript
{
displayName: 'Fields to Set',
name: 'assignments',
type: 'assignmentCollection',
default: {},
},
```
You can see an example in n8n's [Edit Fields (Set) node](https://github.com/n8n-io/n8n/tree/0faeab1228e26d69a2a93bdb2f89523cca1e4036/packages/nodes-base/nodes/Set/v2){:target=_blank .external-link}:

## Fixed collection
Use the `fixedCollection` type to group fields that are semantically related.
```typescript
{
displayName: 'Metadata',
name: 'metadataUi',
placeholder: 'Add Metadata',
type: 'fixedCollection',
default: '',
typeOptions: {
multipleValues: true,
},
description: '',
options: [
{
name: 'metadataValues',
displayName: 'Metadata',
values: [
{
displayName: 'Name',
name: 'name',
type: 'string',
default: 'Name of the metadata key to add.',
},
{
displayName: 'Value',
name: 'value',
type: 'string',
default: '',
description: 'Value to set for the metadata key.',
},
],
},
],
displayOptions: { // the resources and operations to display this element with
show: {
resource: [
// comma-separated list of resource names
],
operation: [
// comma-separated list of operation names
]
}
},
}
```

## Resource locator

The resource locator element helps users find a specific resource in an external service, such as a card or label in Trello.
The following options are available:
* ID
* URL
* List: allows users to select or search from a prepopulated list. This option requires more coding, as you must populate the list, and handle searching if you choose to support it.
You can choose which types to include.
Example:
```typescript
{
displayName: 'Card',
name: 'cardID',
type: 'resourceLocator',
default: '',
description: 'Get a card',
modes: [
{
displayName: 'ID',
name: 'id',
type: 'string',
hint: 'Enter an ID',
validation: [
{
type: 'regex',
properties: {
regex: '^[0-9]',
errorMessage: 'The ID must start with a number',
},
},
],
placeholder: '12example',
// How to use the ID in API call
url: '=http://api-base-url.com/?id={{$value}}',
},
{
displayName: 'URL',
name: 'url',
type: 'string',
hint: 'Enter a URL',
validation: [
{
type: 'regex',
properties: {
regex: '^http',
errorMessage: 'Invalid URL',
},
},
],
placeholder: 'https://example.com/card/12example/',
// How to get the ID from the URL
extractValue: {
type: 'regex',
regex: 'example.com/card/([0-9]*.*)/',
},
},
{
displayName: 'List',
name: 'list',
type: 'list',
typeOptions: {
// You must always provide a search method
// Write this method within the methods object in your base file
// The method must populate the list, and handle searching if searchable: true
searchListMethod: 'searchMethod',
// If you want users to be able to search the list
searchable: true,
// Set to true if you want to force users to search
// When true, users can't browse the list
// Or false if users can browse a list
searchFilterRequired: true,
},
},
],
displayOptions: {
// the resources and operations to display this element with
show: {
resource: [
// comma-separated list of resource names
],
operation: [
// comma-separated list of operation names
],
},
},
},
```
Refer to the following for live examples:
* Refer to [`CardDescription.ts`](https://github.com/n8n-io/n8n/blob/master/packages/nodes-base/nodes/Trello/CardDescription.ts){:target=_blank .external-link} and [`Trello.node.ts`](https://github.com/n8n-io/n8n/blob/master/packages/nodes-base/nodes/Trello/Trello.node.ts){:target=_blank .external-link} in n8n's Trello node for an example of a list with search that includes `searchFilterRequired: true`.
* Refer to [`GoogleDrive.node.ts`](https://github.com/n8n-io/n8n/blob/master/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts){:target=_blank .external-link} for an example where users can browse the list or search.
## Resource mapper
If your node performs insert, update, or upsert operations, you need to send data from the node in a format supported by the service you're integrating with. A common pattern is to use a Set node before the node that sends data, to convert the data to match the schema of the service you're connecting to. The resource mapper UI component provides a way to get data into the required format directly within the node, rather than using a Set node. The resource mapper component can also validate input data against the schema provided in the node, and cast input data into the expected type.
/// note | Mapping and matching
Mapping is the process of setting the input data to use as values when updating row(s). Matching is the process of using column names to identify the row(s) to update.
///
```js
{
displayName: 'Columns',
name: 'columns', // The name used to reference the element UI within the code
type: 'resourceMapper', // The UI element type
default: {
// mappingMode can be defined in the component (mappingMode: 'defineBelow')
// or you can attempt automatic mapping (mappingMode: 'autoMapInputData')
mappingMode: 'defineBelow',
// Important: always set default value to null
value: null,
},
required: true,
// See "Resource mapper type options interface" below for the full typeOptions specification
typeOptions: {
resourceMapper: {
resourceMapperMethod: 'getMappingColumns',
mode: 'update',
fieldWords: {
singular: 'column',
plural: 'columns',
},
addAllFields: true,
multiKeyMatch: true,
supportAutoMap: true,
matchingFieldsLabels: {
title: 'Custom matching columns title',
description: 'Help text for custom matching columns',
hint: 'Below-field hint for custom matching columns',
},
},
},
},
```
Refer to the [Postgres node (version 2)](https://github.com/n8n-io/n8n/tree/master/packages/nodes-base/nodes/Postgres/v2){:target=_blank .external-link} for a live example using a database schema.
Refer to the [Google Sheets node (version 2)](https://github.com/n8n-io/n8n/tree/master/packages/nodes-base/nodes/Google/Sheet/v2){:target=_blank .external-link} for a live example using a schema-less service.
### Resource mapper type options interface
The `typeOptions` section must implement the following interface:
```js
export interface ResourceMapperTypeOptions {
// The name of the method where you fetch the schema
// Refer to the Resource mapper method section for more detail
resourceMapperMethod: string;
// Choose the mode for your operation
// Supported modes: add, update, upsert
mode: 'add' | 'update' | 'upsert';
// Specify labels for fields in the UI
fieldWords?: { singular: string; plural: string };
// Whether n8n should display a UI input for every field when node first added to workflow
// Default is true
addAllFields?: boolean;
// Specify a message to show if no fields are fetched from the service
// (the call is successful but the response is empty)
noFieldsError?: string;
// Whether to support multi-key column matching
// multiKeyMatch is for update and upsert only
// Default is false
// If true, the node displays a multi-select dropdown for the matching column selector
multiKeyMatch?: boolean;
// Whether to support automatic mapping
// If false, n8n hides the mapping mode selector field and sets mappingMode to defineBelow
supportAutoMap?: boolean;
// Custom labels for the matching columns selector
matchingFieldsLabels?: {
title?: string;
description?: string;
hint?: string;
};
}
```
### Resource mapper method
This method contains your node-specific logic for fetching the data schema. Every node must implement its own logic for fetching the schema, and setting up each UI field according to the schema.
It must return a value that implements the `ResourceMapperFields` interface:
```js
interface ResourceMapperField {
// Field ID as in the service
id: string;
// Field label
displayName: string;
// Whether n8n should pre-select the field as a matching field
// A matching field is a column used to identify the rows to modify
defaultMatch: boolean;
// Whether the field can be used as a matching field
canBeUsedToMatch?: boolean;
// Whether the field is required by the schema
required: boolean;
// Whether to display the field in the UI
// If false, can't be used for matching or mapping
display: boolean;
// The data type for the field
// These correspond to UI element types
// Supported types: string, number, dateTime, boolean, time, array, object, options
type?: FieldType;
// Added at runtime if the field is removed from mapping by the user
removed?: boolean;
// Specify options for enumerated types
options?: INodePropertyOptions[];
}
```
Refer to the [Postgres resource mapping method](https://github.com/n8n-io/n8n/blob/master/packages/nodes-base/nodes/Postgres/v2/methods/resourceMapping.ts){:target=_blank .external-link} and [Google Sheets resource mapping method](https://github.com/n8n-io/n8n/blob/master/packages/nodes-base/nodes/Google/Sheet/v2/methods/resourceMapping.ts){:target=_blank .external-link} for live examples.
## JSON
```typescript
{
displayName: 'Content (JSON)',
name: 'content',
type: 'json',
default: '',
description: '',
displayOptions: { // the resources and operations to display this element with
show: {
resource: [
// comma-separated list of resource names
],
operation: [
// comma-separated list of operation names
]
}
},
}
```

## HTML
The HTML editor allows users to create HTML templates in their workflows. The editor supports standard HTML, CSS in `<style>` tags, and expressions wrapped in `{{}}`. Users can add `<script>` tags to pull in additional JavaScript. n8n doesn't run this JavaScript during workflow execution.
```js
{
displayName: 'HTML Template', // The value the user sees in the UI
name: 'html', // The name used to reference the element UI within the code
type: 'string',
typeOptions: {
editor: 'htmlEditor',
},
default: placeholder, // Loads n8n's placeholder HTML template
noDataExpression: true, // Prevent using an expression for the field
description: 'HTML template to render',
},
```
Refer to [`Html.node.ts`](https://github.com/n8n-io/n8n/blob/master/packages/nodes-base/nodes/Html/Html.node.ts){:target=_blank .external-link} for a live example.
## Notice
Display a yellow box with a hint or extra info. Refer to [Node UI design](/integrations/creating-nodes/plan/node-ui-design.md) for guidance on writing good hints and info text.
```js
{
displayName: 'Your text here',
name: 'notice',
type: 'notice',
default: '',
},
```

## Hints
There are two types of hints: parameter hints and node hints:
* Parameter hints are small lines of text below a user input field.
* Node hints are a more powerful and flexible option than [Notice](#notice). Use them to display longer hints, in the input panel, output panel, or node details view.
### Add a parameter hint
Add the `hint` parameter to a UI element:
```ts
{
displayName: 'URL',
name: 'url',
type: 'string',
hint: 'Enter a URL',
...
}
```
### Add a node hint
Define the node's hints in the `hints` property within the node `description`:
```ts
description: INodeTypeDescription = {
...
hints: [
{
// The hint message. You can use HTML.
message: "This node has many input items. Consider enabling <b>Execute Once</b> in the node\'s settings.",
// Choose from: info, warning, danger. The default is 'info'.
// Changes the color. info (grey), warning (yellow), danger (red)
type: 'info',
// Choose from: inputPane, outputPane, ndv. By default n8n displays the hint in both the input and output panels.
location: 'outputPane',
// Choose from: always, beforeExecution, afterExecution. The default is 'always'
whenToDisplay: 'beforeExecution',
// Optional. An expression. If it resolves to true, n8n displays the message. Defaults to true.
displayCondition: '={{ $parameter["operation"] === "select" && $input.all().length > 1 }}'
}
]
...
}
```
### Add a dynamic hint to a programmatic-style node
In programmatic-style nodes you can create a dynamic message that includes information from the node execution. As it relies on the node output data, you can't display this type of hint until after execution.
```ts
if (operation === 'select' && items.length > 1 && !node.executeOnce) {
// Expects two parameters: NodeExecutionData and an array of hints
return new NodeExecutionOutput(
[returnData],
[
{
message: `This node ran ${items.length} times, once for each input item. To run for the first item only, enable <b>Execute once</b> in the node settings.`,
location: 'outputPane',
},
],
);
}
return [returnData];
```
For a live example of a dynamic hint in a programmatic-style node, view the [Split Out node code](https://github.com/n8n-io/n8n/blob/master/packages/nodes-base/nodes/Transform/SplitOut/SplitOut.node.ts#L266){:target=_blank .external-link}.
|