brutusin / json-forms

JSON Schema to HTML form generator, supporting dynamic subschemas (on the fly resolution). Extensible and customizable library with zero dependencies. Bootstrap add-ons provided
http://brutusin.org/json-forms
Apache License 2.0
606 stars 168 forks source link

SchemaResolver with array of objects of dynamic #109

Open abelchun39 opened 6 years ago

abelchun39 commented 6 years ago

I had an array of objects A and each of object contains filter. Each filter options will display different kinds of forms objects dynamically.

Based on the issue https://github.com/brutusin/json-forms/issues/22, the dynamic done in the first layer of the object. But I have array of objects A that doesn't work for each display.

var schema = {
  "properties": {
    "ObjectA": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": { "filter": ...., "criteria": { "dependOn": ['filter'] } }
      }
    }
  }
}
var dynamicSchema = {
  "age": { type: "Object",  number: 21 },
  "country": { type: "Object", name: "US" }
}

var BrutusinForms = brutusin["json-forms"];
this.bf = BrutusinForms.create(schema);
this.bf.schemaResolver = (names, data, cb) => {
  data.ObjectA.map((obj, ind) => {
  schemas["$.ObjectA[" + ind + "].criteria"] = dynamicSchema[obj.filter]
  }
  cb(schemas);
}
this.bf.render(this.$refs.manageContainer);

The name always outputs schemas["$.demographic[#].criteria"] no matter which filter I add. If I add schemas["$.demographic"], it works for me without the filter but the dynamic schema objects.

idelvall commented 6 years ago

https://github.com/brutusin/json-forms/blob/master/README.md#status

OYE93 commented 5 years ago

hello, did you solve this problem? I also meet this problem, thanks!