-
Notifications
You must be signed in to change notification settings - Fork 1
/
random-item.html
76 lines (68 loc) · 2.49 KB
/
random-item.html
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
<script type="text/javascript">
RED.nodes.registerType('random-item', {
category: 'function',
color: '#cc99cc',
inputs: 1,
outputs: 1,
icon: 'random-item.png',
label: function () { return this.name || 'random-item'; },
defaults: {
name: { value: '' },
input: { value: 'payload' },
inputType: { value: 'msg' },
output: { value: 'payload' },
outputType: { value: 'msg' },
number: { value: 1 },
},
oneditprepare: () => {
$('#node-input-input').typedInput({
types: ['msg', 'flow', 'global', 'json', 'jsonata', "env"],
typeField: '#node-input-inputType',
});
$('#node-input-output').typedInput({
types: ['msg', 'flow', 'global'],
typeField: '#node-input-outputType',
});
$('#node-input-number').spinner({ min: 1 });
},
});
</script>
<script type="text/x-red" data-template-name="random-item">
<div class="form-row">
<label for="node-input-name">Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-input">Input</label>
<input type="text" id="node-input-input" style="width: 70%">
<input type="hidden" id="node-input-inputType">
</div>
<div class="form-row">
<label for="node-input-number">Max # items returned</label>
<input type="text" id="node-input-number" style="text-align:end; width:50px !important">
</div>
<div class="form-row">
<label for="node-input-input">Output</label>
<input type="text" id="node-input-output" style="width: 70%">
<input type="hidden" id="node-input-outputType">
</div>
</script>
<script type="text/x-red" data-help-name="random-item">
<p>A node that selects a random item from an array.</p>
<h3>Inputs</h3>
<p>Input needs to be in a JSON formatted array.</p>
<p>Examples of inputs:</p>
<ul>
<li><pre>["first", "second", "third", "fourth"]</pre></li>
<li><pre>[1,2,3,4,5]</pre></li>
<li>
<pre>[
{"name": "George Jetson", "role": "father"},
{"name": "Jane Jetson", "role": "mother"},
{"name": "Judy Jetson", "role": "daugter"},
{"name": "Elroy Jetson", "role": "son"}
]</pre></li>
</ul>
<h3>Outputs</h3>
Output will either be a single data type or an array of items if the <code>Max # of items</code> is greater than one.
</script>