Skip to content

Commit 15354b3

Browse files
author
Omri Schwarz
committed
Remove the testing text frm the element meant to display the resulting
JSON.
1 parent fabb5d1 commit 15354b3

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

dist/js/brutusin-json-forms.js

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,34 @@ if (typeof brutusin === "undefined") {
315315
input.onchange();
316316
appendChild(container, input, s);
317317
};
318+
renderers["oneOf"] = function (container, id, parentObject, propertyProvider, value) {
319+
var schemaId = getSchemaId(id);
320+
var s = getSchema(schemaId);
321+
var input = document.createElement("select");
322+
var display = document.createElement("div");
323+
display.innerHTML="selected object goes here";
324+
var selectedIndex = 0;
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);
318344

345+
}
319346
renderers["object"] = function (container, id, parentObject, propertyProvider, value) {
320347

321348
function createStaticPropertyProvider(propname) {
@@ -486,7 +513,7 @@ if (typeof brutusin === "undefined") {
486513
appendChild(container, table, s);
487514
}
488515
};
489-
516+
// end of object renderer
490517
renderers["array"] = function (container, id, parentObject, propertyProvider, value) {
491518
function addItem(current, table, id, value) {
492519
var schemaId = getSchemaId(id);
@@ -574,7 +601,7 @@ if (typeof brutusin === "undefined") {
574601
}
575602
appendChild(container, div, s);
576603
};
577-
604+
// end of array render
578605
/**
579606
* Renders the form inside the the container, with the specified data preloaded
580607
* @param {type} c container
@@ -736,7 +763,16 @@ if (typeof brutusin === "undefined") {
736763
} else if (schema.type === "array") {
737764
pseudoSchema.items = name + "[#]";
738765
populateSchemaMap(pseudoSchema.items, schema.items);
739-
}
766+
} else if (schema.hasOwnProperty("oneOf")) {
767+
pseudoSchema.oneOf = new Array();
768+
pseudoSchema.type = "oneOf";
769+
for (var i in schema.oneOf) {
770+
console.log(schema.oneOf[i]);
771+
var childProp = name + "." + i;
772+
pseudoSchema.oneOf[i] = childProp;
773+
populateSchemaMap(childProp, schema.oneOf[i]);
774+
}
775+
}
740776
if (schema.hasOwnProperty("dependsOn")) {
741777
if (schema.dependsOn === null) {
742778
schema.dependsOn = ["$"];
@@ -824,6 +860,7 @@ if (typeof brutusin === "undefined") {
824860
}
825861

826862
function render(titleContainer, container, id, parentObject, propertyProvider, value) {
863+
console.log(id);
827864
var schemaId = getSchemaId(id);
828865
var s = getSchema(schemaId);
829866
renderInfoMap[schemaId] = new Object();
@@ -834,6 +871,7 @@ if (typeof brutusin === "undefined") {
834871
renderInfoMap[schemaId].value = value;
835872
clear(titleContainer);
836873
clear(container);
874+
console.log(s.type,id,s);
837875
var r = renderers[s.type];
838876
if (r && !s.dependsOn) {
839877
if (s.title) {

src/js/brutusin-json-forms.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ if (typeof brutusin === "undefined") {
320320
var s = getSchema(schemaId);
321321
var input = document.createElement("select");
322322
var display = document.createElement("div");
323-
display.innerHTML="selected object goes here";
323+
display.innerHTML="";
324324
var selectedIndex = 0;
325325
input.type = "select";
326326
input.schema = schemaId;

0 commit comments

Comments
 (0)