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 @@
(function (window, rJS) {
"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)
.setState({
type: 'checkbox',
......@@ -12,7 +25,7 @@
.declareMethod('render', function (options) {
var field_json = options.field_json || {},
state_dict = {
checked: field_json.value || field_json.default,
checked: asBool(field_json.value || field_json.default),
editable: field_json.editable,
name: field_json.key,
title: field_json.title,
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>955.51162.4768.35123</string> </value>
<value> <string>962.4135.1398.9574</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1482843222.46</float>
<float>1505315155.72</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