Skip to content

Commit 8898ce4

Browse files
authored
Merge pull request #1211 from bartbutenaers/form-dropdown-support
Form dropdown support
2 parents 3ac0b6b + 7eeb578 commit 8898ce4

File tree

6 files changed

+365
-137
lines changed

6 files changed

+365
-137
lines changed

docs/nodes/widgets/ui-form.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,19 @@ props:
1919
Two Columns: Will render the form as a two-column layout.
2020
Reset on Submit: If checked, the form will be reset to an empty state after the form is submitted.
2121
Topic: Defines how to compute the topic, included in the `msg` object, when the form is submitted.
22+
Dropdown Options:
23+
dynamic: true
24+
description: This list can define options for multiple dropdown/select field in a single form.
2225
dynamic:
2326
Label:
2427
payload: msg.ui_update.label
2528
structure: ["String"]
2629
Options:
2730
payload: msg.ui_update.options
2831
structure: ["Array<Object>"]
32+
Dropdown Options:
33+
payload: msg.ui_update.dropdownOptions
34+
structure: ["Array<{ dropdown: <string>, key: <string>, label: <string> }>"]
2935
Class:
3036
payload: msg.class
3137
structure: ["String"]
@@ -164,6 +170,27 @@ If you want to override the configuration for your `ui-form`, and provide detail
164170
"required": true
165171
}
166172
```
173+
#### Element: Dropdown
174+
175+
```json
176+
{
177+
"type": "dropdown",
178+
"label": "Dropdown",
179+
"key": "selection"
180+
}
181+
```
182+
183+
### Defining Dropdown Options
184+
185+
If you want to override the configuration for your `ui-form`, and provide details of your dropdown options after your Node-RED flow has been deployed, you can do so by passing a `msg.ui_update.dropdownOptions` value. This value should be an array of objects, where each object represents a dropdown element. Each object should have the following properties:
186+
187+
```json
188+
[{
189+
"dropdown": "Dropdown Name",
190+
"value": "1",
191+
"label": "Option 1"
192+
}]
193+
```
167194

168195

169196
## Example

nodes/widgets/locales/en-US/ui_form.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
</ul>
1414
<p>Optionally the <b>Topic</b> field can be used to set the <code>msg.topic</code> property.</p>
1515
<p>The Cancel button can be hidden by setting it's value to be blank "".</p>
16+
<p>When form elements of type 'dropdown' have been used, the corresponding dropdown options can be specified in the second tabsheet.</p>
1617
<h3>Dynamic Properties (Inputs)</h3>
1718
<p>Any of the following can be appended to a <code>msg.ui_update</code> in order to override or set properties on this node at runtime.</p>
1819
<dl class="message-properties">
@@ -23,6 +24,10 @@ <h3>Dynamic Properties (Inputs)</h3>
2324
<dt class="optional">options <span class="property-type">array</span></dt>
2425
<dd>Re-define the form's elements by passing an array of objects that define the elements you want to see in your form. </dd>
2526
</dl>
27+
<dl class="message-properties">
28+
<dt class="optional">dropdownOptions <span class="property-type">array</span></dt>
29+
<dd>Re-define the form's dropdown options by passing an array of objects that define the options you want to see in your dropdown. </dd>
30+
</dl>
2631
<dl class="message-properties">
2732
<dt class="optional">class <span class="property-type">string</span></dt>
2833
<dd>Add a CSS class, or more, to the form at runtime.</dd>
@@ -64,4 +69,4 @@ <h5>Element: Email</h5>
6469
"key": "email",
6570
"required": true
6671
}</code></pre>
67-
</script>
72+
</script>

nodes/widgets/locales/en-US/ui_form.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
{
22
"ui-form": {
33
"label": {
4+
"dropdown": "Dropdown",
45
"group": "Group",
56
"size": "Size",
7+
"key": "Key",
68
"label": "Label",
9+
"value": "Value",
710
"optionalLabel": "optional label",
811
"className": "Class",
912
"classNamePlaceholder": "Optional CSS class name(s)",
1013
"formElements": "Form elements",
14+
"dropdownOptions": "Dropdown options",
1115
"type": "Type",
1216
"required": "Required",
1317
"rows": "Rows",
1418
"remove": "Remove",
15-
"egName": "e.g. Name",
16-
"egName2": "e.g. name",
19+
"egLabel": "e.g. Option 1",
20+
"egValue": "e.g. 1",
1721
"text": "Text",
1822
"multiline": "Multiline",
1923
"number": "Number",
@@ -23,6 +27,7 @@
2327
"switch": "Switch",
2428
"date": "Date",
2529
"time": "Time",
30+
"element": "element",
2631
"buttons": "Buttons",
2732
"submit": "submit",
2833
"submitButtonText": "submit button text",

0 commit comments

Comments
 (0)