expandable fields load correct previous values on initiation. minor corrections

parent 00f5c97e
...@@ -67,6 +67,7 @@ ...@@ -67,6 +67,7 @@
gadget.props.element.children[2].style.display = ''; gadget.props.element.children[2].style.display = '';
inputs = gadget.props.element.children[2] inputs = gadget.props.element.children[2]
.getElementsByTagName("input"); .getElementsByTagName("input");
// find the inputs that are direct children of the gadgets element
for (i = 0; i <= inputs.length-1; i += 1) { for (i = 0; i <= inputs.length-1; i += 1) {
if (inputs[i].parentNode.parentNode.parentNode === if (inputs[i].parentNode.parentNode.parentNode ===
gadget.props.element.children[2]) { gadget.props.element.children[2]) {
...@@ -75,12 +76,14 @@ ...@@ -75,12 +76,14 @@
} }
lbls = gadget.props.element.children[2] lbls = gadget.props.element.children[2]
.getElementsByTagName("label"); .getElementsByTagName("label");
// find the labels that are direct children of the gadgets element
for (i = 0; i <= lbls.length-1; i += 1) { for (i = 0; i <= lbls.length-1; i += 1) {
if (lbls[i].parentNode === if (lbls[i].parentNode ===
gadget.props.element.children[2]) { gadget.props.element.children[2]) {
labels.push(lbls[i]); labels.push(lbls[i]);
} }
} }
for (i = 0; i <= Object.keys(properties_dict).length-1; i += 1) { for (i = 0; i <= Object.keys(properties_dict).length-1; i += 1) {
sub_title = Object.keys(properties_dict)[i]; sub_title = Object.keys(properties_dict)[i];
console.log("sub_title"); console.log("sub_title");
...@@ -126,10 +129,13 @@ ...@@ -126,10 +129,13 @@
} }
default_value = properties_dict[sub_title].default; default_value = properties_dict[sub_title].default;
// previous value // find previous value if any
if (gadget.props.options.value[prop_name]) { if (gadget.props.options.value[prop_name]) {
if (gadget.props.options.value[prop_name][sub_title]) {
previous_value = gadget.props.options.value[prop_name][sub_title]; previous_value = gadget.props.options.value[prop_name][sub_title];
} }
}
for (j = 0; j <= inps.length-1; j += 1) { for (j = 0; j <= inps.length-1; j += 1) {
// check if the input is one of a sub-gadget // check if the input is one of a sub-gadget
// do not proceed if yes // do not proceed if yes
...@@ -313,8 +319,8 @@ ...@@ -313,8 +319,8 @@
gadget.props.field_gadget_list.push(sub_gadget); gadget.props.field_gadget_list.push(sub_gadget);
}); });
} }
// update the listfield of the expandable field
function addListField(options) { function updateListField(options) {
console.log("ADDLISTFIELD EXPANDABLEFIELDSET 1"); console.log("ADDLISTFIELD EXPANDABLEFIELDSET 1");
var select = gadget.props.element.getElementsByTagName('select')[0], var select = gadget.props.element.getElementsByTagName('select')[0],
i, i,
...@@ -335,7 +341,6 @@ ...@@ -335,7 +341,6 @@
} }
select.innerHTML += tmp; select.innerHTML += tmp;
} }
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
// function that finds the different types of fields that are // function that finds the different types of fields that are
// requested and calculates how many times each one of them // requested and calculates how many times each one of them
...@@ -485,13 +490,23 @@ ...@@ -485,13 +490,23 @@
} }
} }
} }
for (ind = 0; ind <= oneOf_list.length - 1; ind += 1) {
if (oneOf_list[ind].title === string_value) {
value
= (gadget.props.options.value || {})[oneOf_list[ind].title]
=== undefined
? oneOf_list[ind].default
: gadget.props.options.value[oneOf_list[ind].title];
break;
}
}
console.log("abstract_definition for " + index); console.log("abstract_definition for " + index);
console.log(ab_definition); console.log(ab_definition);
// add a field with abstract definition // add a field with abstract definition
addField( addField(
ab_definition.title, ab_definition.title,
ab_definition, ab_definition,
"undefined" value
); );
// find out if the oneOf_list item should be initiated // find out if the oneOf_list item should be initiated
// (if it is the selected one (string_value)) // (if it is the selected one (string_value))
...@@ -507,6 +522,7 @@ ...@@ -507,6 +522,7 @@
property_def : oneOf_list[ind], property_def : oneOf_list[ind],
value : value value : value
}; };
break;
} }
} }
} else { } else {
...@@ -526,7 +542,7 @@ ...@@ -526,7 +542,7 @@
=== undefined === undefined
? prop_definition.default ? prop_definition.default
: gadget.props.options.value[prop_name]; : gadget.props.options.value[prop_name];
addListField({ updateListField({
key: prop_name, key: prop_name,
value: string_value, value: string_value,
property_definition: prop_definition property_definition: prop_definition
...@@ -536,7 +552,6 @@ ...@@ -536,7 +552,6 @@
}); });
return queue; return queue;
}) })
// getContent of all subfields // getContent of all subfields
.declareMethod("getContent", function () { .declareMethod("getContent", function () {
console.log("GETCONTENT EXPANDABLEFIELDSET 1"); console.log("GETCONTENT EXPANDABLEFIELDSET 1");
......
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