Commit c844603b authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_jio: Render an text input if the value isnt Integer/Float

   This is a failover approach to prevent the user loose its value if it is not complaint with the field
parent 48fc1d6b
......@@ -128,6 +128,34 @@
return input;
}
function testInteger(value) {
var parsed_value;
if (value === undefined || value === "") {
// Value is empty so it is ok to render the field
return true;
}
parsed_value = parseFloat(value);
if (!isNaN(parsed_value) && ((parsed_value % 1) === 0)) {
return true;
}
return false;
}
function testNumber(value) {
var parsed_value;
if (value === undefined || value === "") {
// Value is empty so it is ok to render the field
return true;
}
parsed_value = parseFloat(value);
if (!isNaN(parsed_value)) {
return true;
}
return false;
}
function render_field(json_field, default_value, is_required, editable) {
var input,
data_format,
......@@ -169,9 +197,9 @@
domsugar_input_dict.value = default_value;
}
if (json_field.type === "integer") {
if (json_field.type === "integer" && testInteger(default_value)) {
domsugar_input_dict.type = "number";
} else if (json_field.type === "number") {
} else if (json_field.type === "number" && testNumber(default_value)) {
domsugar_input_dict.type = "number";
domsugar_input_dict.step = "any";
} else if (json_field.type === "hidden") {
......
......@@ -282,7 +282,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1008.808.61596.8721</string> </value>
<value> <string>1008.44140.3254.1792</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -302,7 +302,7 @@
</tuple>
<state>
<tuple>
<float>1682619529.51</float>
<float>1685133283.74</float>
<string>UTC</string>
</tuple>
</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