Skip to content

Commit a6ab393

Browse files
committed
Merge branch 'pr/11'
# Conflicts: # dist/js/brutusin-json-forms-bootstrap.js # dist/js/brutusin-json-forms.js # dist/js/brutusin-json-forms.min.js # src/js/brutusin-json-forms.js
2 parents acef6e6 + b9e59e9 commit a6ab393

File tree

1 file changed

+48
-12
lines changed

1 file changed

+48
-12
lines changed

src/js/brutusin-json-forms.js

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ if (typeof brutusin === "undefined") {
8787

8888
BrutusinForms.addDecorator = function (f) {
8989
BrutusinForms.decorators[BrutusinForms.decorators.length] = f;
90-
}
90+
};
9191

9292
BrutusinForms.onResolutionStarted = function (element) {
93-
}
93+
};
9494

9595
BrutusinForms.onResolutionFinished = function (element) {
96-
}
96+
};
9797

9898
BrutusinForms.onValidationError = function (element, message) {
9999
element.focus();
@@ -168,7 +168,7 @@ if (typeof brutusin === "undefined") {
168168
var option = document.createElement("option");
169169
var textNode = document.createTextNode("");
170170
option.value = "";
171-
appendChild(option, textNode, s)
171+
appendChild(option, textNode, s);
172172
appendChild(input, option, s);
173173
}
174174
var selectedIndex = 0;
@@ -316,7 +316,32 @@ if (typeof brutusin === "undefined") {
316316
input.onchange();
317317
appendChild(container, input, s);
318318
};
319-
319+
renderers["oneOf"] = function (container, id, parentObject, propertyProvider, value) {
320+
var schemaId = getSchemaId(id);
321+
var s = getSchema(schemaId);
322+
var input = document.createElement("select");
323+
var display = document.createElement("div");
324+
display.innerHTML = "";
325+
input.type = "select";
326+
input.schema = schemaId;
327+
var noption = document.createElement("option");
328+
noption.value = null;
329+
appendChild(input, noption, s);
330+
for (var i = 0; i < s.oneOf.length; i++) {
331+
var option = document.createElement("option");
332+
var propId = id + "." + i;
333+
var ss = getSchema(propId);
334+
var textNode = document.createTextNode(ss.title);
335+
option.value = s.oneOf[i];
336+
appendChild(option, textNode, s);
337+
appendChild(input, option, s);
338+
}
339+
input.onchange = function () {
340+
render(null, display, id + "." + (input.selectedIndex - 1), parentObject, propertyProvider, value);
341+
};
342+
appendChild(container, input, s);
343+
appendChild(container, display, s);
344+
};
320345
renderers["object"] = function (container, id, parentObject, propertyProvider, value) {
321346

322347
function createStaticPropertyProvider(propname) {
@@ -354,7 +379,7 @@ if (typeof brutusin === "undefined") {
354379
if (!nameInput.value) {
355380
return BrutusinForms.messages["addpropNameRequired"];
356381
}
357-
}
382+
};
358383
var pp = createPropertyProvider(
359384
function () {
360385
if (nameInput.value) {
@@ -364,7 +389,7 @@ if (typeof brutusin === "undefined") {
364389
}
365390
},
366391
function (oldPropertyName) {
367-
if(pp.getValue()===oldPropertyName){
392+
if (pp.getValue() === oldPropertyName) {
368393
return;
369394
}
370395
if (!oldPropertyName) {
@@ -487,7 +512,7 @@ if (typeof brutusin === "undefined") {
487512
appendChild(container, table, s);
488513
}
489514
};
490-
515+
// end of object renderer
491516
renderers["array"] = function (container, id, parentObject, propertyProvider, value) {
492517
function addItem(current, table, id, value) {
493518
var schemaId = getSchemaId(id);
@@ -558,7 +583,7 @@ if (typeof brutusin === "undefined") {
558583
if (s.maxItems && s.maxItems < table.rows.length) {
559584
return BrutusinForms.messages["maxItems"].format(s.maxItems);
560585
}
561-
}
586+
};
562587
addButton.onclick = function () {
563588
addItem(current, table, id + "[#]", null);
564589
};
@@ -575,11 +600,11 @@ if (typeof brutusin === "undefined") {
575600
}
576601
appendChild(container, div, s);
577602
};
578-
603+
// end of array render
579604
/**
580605
* Renders the form inside the the container, with the specified data preloaded
581606
* @param {type} c container
582-
* @param {type} initialValue json data
607+
* @param {type} data json data
583608
* @returns {undefined}
584609
*/
585610
obj.render = function (c, data) {
@@ -737,6 +762,15 @@ if (typeof brutusin === "undefined") {
737762
} else if (schema.type === "array") {
738763
pseudoSchema.items = name + "[#]";
739764
populateSchemaMap(pseudoSchema.items, schema.items);
765+
} else if (schema.hasOwnProperty("oneOf")) {
766+
pseudoSchema.oneOf = new Array();
767+
pseudoSchema.type = "oneOf";
768+
for (var i in schema.oneOf) {
769+
// console.log(schema.oneOf[i]);
770+
var childProp = name + "." + i;
771+
pseudoSchema.oneOf[i] = childProp;
772+
populateSchemaMap(childProp, schema.oneOf[i]);
773+
}
740774
}
741775
if (schema.hasOwnProperty("dependsOn")) {
742776
if (schema.dependsOn === null) {
@@ -772,7 +806,7 @@ if (typeof brutusin === "undefined") {
772806
if (container) {
773807
if (title) {
774808
var titleLabel = document.createElement("label");
775-
if (schema.type != "any" && schema.type != "object" && schema.type != "array") {
809+
if (schema.type !== "any" && schema.type !== "object" && schema.type !== "array") {
776810
titleLabel.htmlFor = getInputId();
777811
}
778812
var titleNode = document.createTextNode(title + ":");
@@ -825,6 +859,7 @@ if (typeof brutusin === "undefined") {
825859
}
826860

827861
function render(titleContainer, container, id, parentObject, propertyProvider, value) {
862+
//console.log(id);
828863
var schemaId = getSchemaId(id);
829864
var s = getSchema(schemaId);
830865
renderInfoMap[schemaId] = new Object();
@@ -835,6 +870,7 @@ if (typeof brutusin === "undefined") {
835870
renderInfoMap[schemaId].value = value;
836871
clear(titleContainer);
837872
clear(container);
873+
// console.log(s.type, id, s);
838874
var r = renderers[s.type];
839875
if (r && !s.dependsOn) {
840876
if (s.title) {

0 commit comments

Comments
 (0)