Commit e4d4b9ba authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_jio: Fixup Number+enum on select tags

   This fixes up the support for the json schema definition for {"type": "number",  "enum": [ 1.0,  2.0] }

   It relies on data-format to overcome the limitation of select fields that only output strings on input.value.
parent b98c187f
...@@ -45,19 +45,28 @@ ...@@ -45,19 +45,28 @@
value: "", value: "",
selected: (default_value === undefined) selected: (default_value === undefined)
})], })],
option_index; option_index,
data_format = "string";
if (json_field.type === "integer" || json_field.type === "number") {
data_format = "number";
}
for (option_index in json_field['enum']) { for (option_index in json_field['enum']) {
if (json_field['enum'].hasOwnProperty(option_index)) { if (json_field['enum'].hasOwnProperty(option_index)) {
option_list.push(domsugar('option', { option_list.push(domsugar('option', {
value: json_field['enum'][option_index], value: json_field['enum'][option_index],
text: json_field['enum'][option_index], text: json_field['enum'][option_index],
selected: (json_field['enum'][option_index] === default_value) "data-format": data_format,
selected: (
json_field['enum'][option_index].toString() === default_value
)
})); }));
} }
} }
return domsugar('select', { return domsugar('select', {
size: 1 size: 1,
"data-format": data_format
}, option_list); }, option_list);
} }
...@@ -335,11 +344,21 @@ ...@@ -335,11 +344,21 @@
} else if (input.value === "false") { } else if (input.value === "false") {
json_dict[input.name] = false; json_dict[input.name] = false;
} else if (input.tagName === "TEXTAREA") { } else if (input.tagName === "TEXTAREA") {
if (input["data-format"] === "string") { if (input.getAttribute("data-format") === "string") {
json_dict[input.name] = input.value; json_dict[input.name] = input.value;
} else { } else {
json_dict[input.name] = input.value.split('\n'); json_dict[input.name] = input.value.split('\n');
} }
} else if (input.tagName === "SELECT") {
if (input.getAttribute("data-format") === "number") {
json_dict[input.name] = parseFloat(input.value);
} else if (input.getAttribute("data-format") === "integer") {
// Don't use parseInt since it will round the value, modifing the
// use input. So we keep it the value.
json_dict[input.name] = parseFloat(input.value);
} else {
json_dict[input.name] = input.value;
}
} else { } else {
json_dict[input.name] = input.value; json_dict[input.name] = input.value;
} }
......
...@@ -280,7 +280,7 @@ ...@@ -280,7 +280,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1000.2445.60408.49186</string> </value> <value> <string>1000.3907.45649.58794</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -298,7 +298,7 @@ ...@@ -298,7 +298,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1651782344.19</float> <float>1651866969.39</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment