Commit 66fd4670 authored by Tomáš Peterka's avatar Tomáš Peterka Committed by Tomáš Peterka

[renderjs_ui] MultiListField does not crash when only one item is selected

/reviewed-on nexedi/erp5!448
parent f5d76b28
...@@ -3,6 +3,13 @@ ...@@ -3,6 +3,13 @@
(function (window, rJS, document, RSVP) { (function (window, rJS, document, RSVP) {
'use strict'; 'use strict';
/* Make sure that returned object is an Array instance. */
function ensureArray(obj) {
if (!obj) {return []; }
if (Array.isArray(obj)) {return obj; }
return [obj];
}
function appendListField(gadget, value, item_list) { function appendListField(gadget, value, item_list) {
var div = document.createElement('div'); var div = document.createElement('div');
gadget.element.appendChild(div); gadget.element.appendChild(div);
...@@ -32,8 +39,9 @@ ...@@ -32,8 +39,9 @@
var field_json = options.field_json || {}, var field_json = options.field_json || {},
item_list = field_json.items, item_list = field_json.items,
state_dict = { state_dict = {
value_list: JSON.stringify(field_json.value || value_list: JSON.stringify(
field_json.default || []), ensureArray(field_json.value || field_json.default)
),
editable: field_json.editable, editable: field_json.editable,
required: field_json.required, required: field_json.required,
name: field_json.key, name: field_json.key,
......
...@@ -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.38785.31645.18483</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>1482843497.05</float> <float>1507301921.45</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