json-editor
json-editor copied to clipboard
How to get the choosen type element on oneOf array
Hi all,
I use a oneOf option on array with some objects defined on definitions part. It gives on the basic.html example :
var editor = new JSONEditor(document.getElementById('editor_holder'),{ schema: { type: "object", format: "grid", title: "Car", properties: { make: { type: "string", enum: [ "Toyota", "BMW", "Honda", "Ford", "Chevy", "VW" ] }, elements: { $ref:"#\/definitions\/elements" }, model: { type: "string" }, year: { type: "integer", enum: [ 1995,1996,1997,1998,1999, 2000,2001,2002,2003,2004, 2005,2006,2007,2008,2009, 2010,2011,2012,2013,2014 ], default: 2008 } }, definitions:{ engine: { type:"object", title: "Engine", properties: { name:{ type:"string", pattern:"^.+$" }, power: { type:"integer" }, itemType: { type: "string", pattern: "^.+$", options:{hidden:true} } }, additionalProperties: false }, body: { type:"object", title: "Body", properties: { name:{ type:"string", pattern:"^.+$" }, size: { type:"integer" }, itemType: { type: "string", pattern: "^.+$", options:{hidden:true} } }, additionalProperties: false }, elements: { type: "typedArray", format: "tabs", title: "Elements list", items: { title: "Element", headerTemplate: "{{i}} - {{self.name}}", oneOf: [ { $ref: "#/definitions/body" }, { $ref: "#/definitions/engine" } ] } } } }, required_by_default: true, disable_edit_json: true, disable_collapse: true, disable_properties: true });
My goal here would to "remember" the selected type and set it on the itemType property of added object. And having for example :
{ make: "Toyota", elements: [ {itemType: "engine", name: "Engine 1", power: 100}, {itemType: "body", name: "Body 1", size: 200}], model: "", year: 2008 }
I tried to define my own editor :
JSONEditor.defaults.editors.typedArray = JSONEditor.defaults.editors.array.extend({ ... });
and for example, using onChildEditorChange method, without success ...
So my questions : is that possible ? What is the best way for doing this ?
Thanks a lot
Nicolas
Would love to see if anybody has thought about this.
some response?