Skip to content

Commit c8fe8d2

Browse files
committed
Add: Custom HTML attributes
1 parent ccc5335 commit c8fe8d2

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

gui.html

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ <h1 id="gui-title"></h1>
2323
<script src="gui.manifest.js"></script>
2424

2525
<script>
26-
// Functions
26+
// Function definitions
2727

2828
/**
2929
* Process values. It does the following things:
@@ -130,26 +130,33 @@ <h1 id="gui-title"></h1>
130130
* @param {object} The input element.
131131
* @param {object} The attributes (blueprint).
132132
*/
133-
const setInputAttributes = (input, attributes) => {
133+
const setInputAttributes = (input, bp) => {
134134
// Placeholder attribute
135-
if (attributes.placeholder) {
136-
input.setAttribute('placeholder', attributes.placeholder)
135+
if (bp.placeholder) {
136+
input.setAttribute('placeholder', bp.placeholder)
137137
}
138138

139139
// Required attribute
140-
if (attributes.required) {
140+
if (bp.required) {
141141
input.setAttribute('required', '')
142142
}
143143

144144
// Checked attribute. Only for radio
145-
if (attributes.checked) {
145+
if (bp.checked) {
146146
input.setAttribute('checked', '')
147147
}
148148

149149
// Disabled attribute
150-
if (attributes.disabled) {
150+
if (bp.disabled) {
151151
input.setAttribute('disabled', '')
152152
}
153+
154+
// Custom attributes
155+
if (bp.attributes) {
156+
for (const attr in bp.attributes) {
157+
input.setAttribute(attr, bp.attributes[attr])
158+
}
159+
}
153160
}
154161

155162
/**

gui.manifest.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const blueprint = {
22
meta: {
33
title: "Demo GUI",
4+
apiVersion: "0.1.0"
45
},
56
command: {
67
prefix: "executable",
@@ -414,5 +415,24 @@ const blueprint = {
414415
},
415416
],
416417
},
418+
{
419+
type: "fieldset",
420+
title: "Advanced Features",
421+
form: [
422+
{
423+
type: "text",
424+
label: "Custom attributes",
425+
help: "Some help message",
426+
attributes: {
427+
"data-username": "myusername"
428+
},
429+
command: {
430+
order: 50,
431+
type: "str",
432+
arg: "--af1",
433+
},
434+
},
435+
],
436+
},
417437
],
418438
}

0 commit comments

Comments
 (0)