Commit ff931799 authored by Tomáš Peterka's avatar Tomáš Peterka Committed by Tomáš Peterka

[renderjs_ui] CheckboxField converts values correctly to boolean

/reviewed-on nexedi/erp5!398
parent 3c9daf1f
...@@ -3,6 +3,19 @@ ...@@ -3,6 +3,19 @@
(function (window, rJS) { (function (window, rJS) {
"use strict"; "use strict";
function asBool(obj) {
if (typeof obj === "boolean") {
return obj;
}
if (typeof obj === "string") {
return obj.toLowerCase() === "true" || obj === "1";
}
if (typeof obj === "number") {
return obj !== 0;
}
return Boolean(obj);
}
rJS(window) rJS(window)
.setState({ .setState({
type: 'checkbox', type: 'checkbox',
...@@ -12,7 +25,7 @@ ...@@ -12,7 +25,7 @@
.declareMethod('render', function (options) { .declareMethod('render', function (options) {
var field_json = options.field_json || {}, var field_json = options.field_json || {},
state_dict = { state_dict = {
checked: field_json.value || field_json.default, checked: asBool(field_json.value || field_json.default),
editable: field_json.editable, editable: field_json.editable,
name: field_json.key, name: field_json.key,
title: field_json.title, title: field_json.title,
......
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>955.51162.4768.35123</string> </value> <value> <string>962.4135.1398.9574</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -248,7 +248,7 @@ ...@@ -248,7 +248,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1482843222.46</float> <float>1505315155.72</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