Commit 016684f2 authored by Tomáš Peterka's avatar Tomáš Peterka Committed by Tomáš Peterka

[renderjs_ui] FloatField and Input uses render() to complete state change

parent 721fcfee
......@@ -4,37 +4,30 @@
"use strict";
rJS(window)
.setState({
type: "number",
// `step` is used for browser-level validation thus a mandatory value
// HTML5 default is 1.0 which is not feasible most of the time thus we
// default to over-sufficiently small value
step: 0.00000001,
required: false,
editable: true,
hidden: false,
name: undefined,
title: undefined,
value: undefined,
text_content: undefined,
// `append` is a string to display next to the field (%, currency...)
append: undefined
})
.declareMethod('render', function (options) {
var field_json = options.field_json || {},
percentage = (field_json.input_style || "").endsWith("%"),
state_dict = {
type: "number",
editable: field_json.editable,
required: field_json.required,
hidden: field_json.hidden,
name: field_json.key,
title: field_json.title,
precision: window.parseFloat(field_json.precision),
hidden: field_json.hidden,
// erp5 always put value into "default"
value: window.parseFloat(field_json.default)
// erp5 always put value into "default" (never "value")
value: window.parseFloat(field_json.default),
text_content: '',
// `step` is used for browser-level validation thus a mandatory value
// HTML5 default is 1.0 which is not feasible most of the time thus we
// default to over-sufficiently small value
step: 0.00000001,
// `append` is a string to display next to the field ("%", "EUR"...)
append: ''
};
if (!window.isNaN(state_dict.value)) {
state_dict.text_content = state_dict.value.toString();
}
if (!window.isNaN(state_dict.precision)) {
state_dict.step = Math.pow(10, -state_dict.precision);
state_dict.value = state_dict.value.toFixed(state_dict.precision);
......@@ -46,11 +39,6 @@
state_dict.append = "%";
}
if (window.isNaN(state_dict.value)) {
state_dict.text_content = ""; // show empty value insted of ugly "NaN"
} else {
state_dict.text_content = state_dict.value.toString();
}
return this.changeState(state_dict);
})
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>962.12584.16558.54920</string> </value>
<value> <string>962.12588.2416.8721</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1505816402.11</float>
<float>1505921992.31</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -15,20 +15,6 @@
}
rJS(window)
.setState({
editable: false,
value: undefined,
checked: undefined,
hidden: false,
title: '',
name: '',
type: 'text',
required: false, // mandatory field
trim: false, // trim content for spaces
focus: undefined, // has focus by default
prepend: undefined, // text to prepend infront the field
append: undefined // text to apend after the field
})
.declareMethod('render', function (options) {
return this.changeState({
......@@ -44,8 +30,8 @@
step: options.step,
hidden: options.hidden,
trim: options.trim || false,
append: options.append,
prepend: options.prepend
append: options.append, // text to apend after the field
prepend: options.prepend // text to prepend infront the field
});
})
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>962.13886.9310.48640</string> </value>
<value> <string>962.13897.43577.15308</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1505894979.84</float>
<float>1505922105.23</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